Submission #34005

# Submission time Handle Problem Language Result Execution time Memory
34005 2017-11-06T03:28:50 Z ngkan146 즐거운 사진 수집 (JOI13_collecting) C++
100 / 100
2373 ms 34784 KB
#include <bits/stdc++.h>
using namespace std;
const int N = (1<<20) + 5;
int n,q,lgn;
int seg[2][4*N], sum[2][25];
void build(int id,int l,int r){
	if (l == r){
		seg[0][id] = seg[1][id] = 0;
		return;
	}
	build(2*id,l,(l+r)/2);
	build(2*id+1,(l+r)/2+1,r);
	seg[0][id] = seg[1][id] = 0;
}
void upd(int type,int id,int l,int r,int pos,int layer){
	if (r < pos || pos < l) return;
	if (l == r){
		seg[type][id] ^= 1;
		return;
	}
	upd(type, 2*id, l, (l+r)/2, pos, layer+1);
	upd(type, 2*id+1, (l+r)/2+1, r, pos, layer+1);
	sum[type][layer] -= (seg[type][id] != -1);
	
	if (seg[type][2*id] == -1 || seg[type][2*id+1] == -1) 
		seg[type][id] = -1;
	else if (seg[type][2*id] != seg[type][2*id+1])
		seg[type][id] = -1;
	else
		seg[type][id] = seg[type][2*id];
	sum[type][layer] += (seg[type][id] != -1);
	
}
void prep(){
	build(1,1,n);
	for(int i=0;i<=lgn;i++)	sum[0][i] = sum[1][i] = (1<<i);
}
int main(){
	scanf("%d %d",&n,&q);
	lgn = n;
	n = (1<<n);
	prep();
	while(q--){
		int type, pos;
		scanf("%d %d",&type,&pos);
		upd(type,1,1,n,pos,0);
		long long res = 0;
		long long used = 0;
		for(int layer = 0;layer <= lgn; layer++){
			
			res += 1ll * ((1ll<<2*layer) - used);
			used = 4ll * sum[0][layer] * sum[1][layer];
			//cout << sum[0][layer] << ' ' << sum[1][layer] << ' ' << res << endl;
		}
		printf("%lld\n",res);
	}
}

Compilation message

collecting.cpp: In function 'int main()':
collecting.cpp:39:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&q);
                      ^
collecting.cpp:45:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&type,&pos);
                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 34784 KB Output is correct
2 Correct 0 ms 34784 KB Output is correct
3 Correct 0 ms 34784 KB Output is correct
4 Correct 0 ms 34784 KB Output is correct
5 Correct 0 ms 34784 KB Output is correct
6 Correct 0 ms 34784 KB Output is correct
7 Correct 0 ms 34784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 34784 KB Output is correct
2 Correct 0 ms 34784 KB Output is correct
3 Correct 0 ms 34784 KB Output is correct
4 Correct 0 ms 34784 KB Output is correct
5 Correct 0 ms 34784 KB Output is correct
6 Correct 0 ms 34784 KB Output is correct
7 Correct 0 ms 34784 KB Output is correct
8 Correct 0 ms 34784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2286 ms 34784 KB Output is correct
2 Correct 2203 ms 34784 KB Output is correct
3 Correct 2113 ms 34784 KB Output is correct
4 Correct 2373 ms 34784 KB Output is correct
5 Correct 2303 ms 34784 KB Output is correct
6 Correct 2119 ms 34784 KB Output is correct
7 Correct 2146 ms 34784 KB Output is correct
8 Correct 2176 ms 34784 KB Output is correct
9 Correct 1966 ms 34784 KB Output is correct
10 Correct 2003 ms 34784 KB Output is correct
11 Correct 2103 ms 34784 KB Output is correct
12 Correct 2203 ms 34784 KB Output is correct
13 Correct 1936 ms 34784 KB Output is correct