Submission #50334

# Submission time Handle Problem Language Result Execution time Memory
50334 2018-06-10T08:11:59 Z top34051 Sterilizing Spray (JOI15_sterilizing) C++17
100 / 100
311 ms 26368 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n,q,k;
int a[maxn];
set<int> pos, del;
long long tree[maxn];
void update(int x, int val) {
	while(x<=n) {
		tree[x] += val;
		x += x&-x;
	}
}
long long query(int x) {
	long long res = 0;
	while(x) {
		res += tree[x];
		x -= x&-x;
	}
	return res;
}
int main() {
	scanf("%d%d%d",&n,&q,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) {
		update(i,a[i]);
		if(a[i]) pos.insert(i);
	}
	while(q--) {
		int type; scanf("%d",&type);
		if(type==1) {
			int x,val; scanf("%d%d",&x,&val);
			update(x, -a[x]);
			a[x] = val;
			update(x, a[x]);
			pos.insert(x);
		}
		else if(type==2) {
			int l,r; scanf("%d%d",&l,&r);
			if(k!=1) {
				del.clear();
				auto it = pos.lower_bound(l);
				while(it!=pos.end() && *it<=r) {
					int x = *it;
					update(x, -a[x]);
					a[x] /= k;
					update(x, a[x]);
					if(a[x]==0) del.insert(x);
					++it;
				}
				for(auto t : del) pos.erase(t);
			}
		}
		else {
			int l,r; scanf("%d%d",&l,&r);
			printf("%lld\n",query(r)-query(l-1));
		}
	}
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:23: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:24:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
                        ~~~~~^~~~~~~~~~~~
sterilizing.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int type; scanf("%d",&type);
             ~~~~~^~~~~~~~~~~~
sterilizing.cpp:32:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x,val; scanf("%d%d",&x,&val);
               ~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int l,r; scanf("%d%d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~
sterilizing.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int l,r; scanf("%d%d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 488 KB Output is correct
3 Correct 4 ms 580 KB Output is correct
4 Correct 7 ms 612 KB Output is correct
5 Correct 8 ms 804 KB Output is correct
6 Correct 7 ms 804 KB Output is correct
7 Correct 8 ms 868 KB Output is correct
8 Correct 8 ms 868 KB Output is correct
9 Correct 9 ms 868 KB Output is correct
10 Correct 8 ms 868 KB Output is correct
11 Correct 9 ms 868 KB Output is correct
12 Correct 9 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 3888 KB Output is correct
2 Correct 103 ms 3888 KB Output is correct
3 Correct 89 ms 5436 KB Output is correct
4 Correct 136 ms 6780 KB Output is correct
5 Correct 125 ms 6932 KB Output is correct
6 Correct 143 ms 6972 KB Output is correct
7 Correct 126 ms 6972 KB Output is correct
8 Correct 135 ms 6972 KB Output is correct
9 Correct 136 ms 7816 KB Output is correct
10 Correct 119 ms 9920 KB Output is correct
11 Correct 142 ms 12244 KB Output is correct
12 Correct 130 ms 14616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 14616 KB Output is correct
2 Correct 25 ms 14616 KB Output is correct
3 Correct 50 ms 14616 KB Output is correct
4 Correct 108 ms 14616 KB Output is correct
5 Correct 115 ms 14616 KB Output is correct
6 Correct 94 ms 14616 KB Output is correct
7 Correct 112 ms 14616 KB Output is correct
8 Correct 94 ms 14616 KB Output is correct
9 Correct 92 ms 14636 KB Output is correct
10 Correct 90 ms 15972 KB Output is correct
11 Correct 91 ms 17236 KB Output is correct
12 Correct 91 ms 18516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 18516 KB Output is correct
2 Correct 133 ms 18516 KB Output is correct
3 Correct 136 ms 18516 KB Output is correct
4 Correct 120 ms 18516 KB Output is correct
5 Correct 207 ms 19080 KB Output is correct
6 Correct 210 ms 19080 KB Output is correct
7 Correct 188 ms 19080 KB Output is correct
8 Correct 245 ms 19080 KB Output is correct
9 Correct 229 ms 21696 KB Output is correct
10 Correct 285 ms 22740 KB Output is correct
11 Correct 222 ms 26092 KB Output is correct
12 Correct 311 ms 26368 KB Output is correct