Submission #222846

# Submission time Handle Problem Language Result Execution time Memory
222846 2020-04-14T08:25:06 Z arnold518 Sterilizing Spray (JOI15_sterilizing) C++14
0 / 100
1879 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, Q, K;
int C[MAXN+10];

vector<int> tree[MAXN*4+10];
int lazy[MAXN*4+10];

vector<int> operator + (const vector<int> &p, const vector<int> &q)
{
	int i, j;
	vector<int> ret;
	ret.resize(max(p.size(), q.size()));

	for(i=0; i<p.size(); i++) ret[ret.size()-p.size()+i]+=p[i];
	for(i=0; i<q.size(); i++) ret[ret.size()-q.size()+i]+=q[i];
	return ret;
}

void init(int node, int tl, int tr)
{
	if(tl==tr)
	{
		int i, j;
		int t=C[tl];
		while(t) tree[node].push_back(t%K), t/=K;
		reverse(tree[node].begin(), tree[node].end());
		return;
	}
	int mid=tl+tr>>1;
	init(node*2, tl, mid);
	init(node*2+1, mid+1, tr);
	tree[node]=tree[node*2]+tree[node*2+1];
}

void busy(int node, int tl, int tr)
{
	int i, j;
	if(lazy[node]==0) return;
	for(i=0; i<lazy[node] && !tree[node].empty(); i++) tree[node].pop_back();
	if(tl!=tr) lazy[node*2]+=lazy[node], lazy[node*2+1]+=lazy[node];
	lazy[node]=0;
}

void update(int node, int tl, int tr, int p)
{
	busy(node, tl, tr);
	if(tr<p || p<tl) return;
	if(tl==tr)
	{
		int i, j;
		int t=C[tl];
		tree[node].clear();
		while(t) tree[node].push_back(t%K), t/=K;
		reverse(tree[node].begin(), tree[node].end());
		return;
	}
	int mid=tl+tr>>1;
	update(node*2, tl, mid, p);
	update(node*2+1, mid+1, tr, p);
	tree[node]=tree[node*2]+tree[node*2+1];
}

vector<int> query(int node, int tl, int tr, int l, int r)
{
	busy(node, tl, tr);
	if(l<=tl && tr<=r) return tree[node];
	if(r<tl || tr<l) return vector<int>();
	int mid=tl+tr>>1;
	return query(node*2, tl, mid, l, r)+query(node*2+1, mid+1, tr, l, r);
}

void update2(int node, int tl, int tr, int l, int r)
{
	busy(node, tl, tr);
	if(r<tl || tr<l) return;
	if(l<=tl && tr<=r)
	{
		lazy[node]++;
		busy(node, tl, tr);
		return;
	}
	int mid=tl+tr>>1;
	update2(node*2, tl, mid, l, r);
	update2(node*2+1, mid+1, tr, l, r);
}

void debug(int node, int tl, int tr)
{
	busy(node, tl, tr);
	for(auto it : tree[node]) printf("%d ", it); printf(" : %d %d %d\n", node, tl, tr);
	if(tl==tr) return;
	int mid=tl+tr>>1;
	debug(node*2, tl, mid);
	debug(node*2+1, mid+1, tr);
}

int main()
{
	int i, j;

	scanf("%d%d%d", &N, &Q, &K);
	for(i=1; i<=N; i++) scanf("%d", &C[i]);
	init(1, 1, N);
	while(Q--)
	{
		int t, l, r;
		scanf("%d%d%d", &t, &l, &r);
		if(t==1)
		{
			C[l]=r;
			update(1, 1, N, l);
		}
		else if(t==2)
		{
			update2(1, 1, N, l, r);
		}
		else
		{
			vector<int> V=query(1, 1, N, l, r);
			ll ans=0;
			for(auto it : V) ans=ans*K+it;
			printf("%lld\n", ans);
		}
	}
}

Compilation message

sterilizing.cpp: In function 'std::vector<int> operator+(const std::vector<int>&, const std::vector<int>&)':
sterilizing.cpp:22:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<p.size(); i++) ret[ret.size()-p.size()+i]+=p[i];
           ~^~~~~~~~~
sterilizing.cpp:23:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<q.size(); i++) ret[ret.size()-q.size()+i]+=q[i];
           ~^~~~~~~~~
sterilizing.cpp:18:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sterilizing.cpp: In function 'void init(int, int, int)':
sterilizing.cpp:31:7: warning: unused variable 'i' [-Wunused-variable]
   int i, j;
       ^
sterilizing.cpp:31:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
sterilizing.cpp:37:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
sterilizing.cpp: In function 'void busy(int, int, int)':
sterilizing.cpp:45:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sterilizing.cpp: In function 'void update(int, int, int, int)':
sterilizing.cpp:58:7: warning: unused variable 'i' [-Wunused-variable]
   int i, j;
       ^
sterilizing.cpp:58:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
sterilizing.cpp:65:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
sterilizing.cpp: In function 'std::vector<int> query(int, int, int, int, int)':
sterilizing.cpp:76:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
sterilizing.cpp: In function 'void update2(int, int, int, int, int)':
sterilizing.cpp:90:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
sterilizing.cpp: In function 'void debug(int, int, int)':
sterilizing.cpp:98:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(auto it : tree[node]) printf("%d ", it); printf(" : %d %d %d\n", node, tl, tr);
  ^~~
sterilizing.cpp:98:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(auto it : tree[node]) printf("%d ", it); printf(" : %d %d %d\n", node, tl, tr);
                                               ^~~~~~
sterilizing.cpp:100:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=tl+tr>>1;
          ~~^~~
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:107:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
sterilizing.cpp:109:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &Q, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:110:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N; i++) scanf("%d", &C[i]);
                      ~~~~~^~~~~~~~~~~~~
sterilizing.cpp:115:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &t, &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1879 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 10616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 18808 KB Output isn't correct
2 Halted 0 ms 0 KB -