# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74606 | cubecube1000 | 즐거운 사진 수집 (JOI13_collecting) | C++14 | 1643 ms | 239848 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const int MAX=(1<<20)+5;
const ll INFLL=0x3f3f3f3f3f3f3f;
bool dist[2][MAX];
int seg[2][MAX],cum[2][MAX],n,q;
int mp[MAX];
ll ans;
void update(int t1,int t2,int val){
//printf("%d %d %d\n",t1,t2,val);
if(t2<=0||t2>=(1<<n)) return;
int v=t2&(-t2);
if(val){if(seg[t1][t2]++==0) cum[t1][v]++, ans+=(ll)((1<<(n-mp[v]-1))-cum[!t1][v]);}
else{if(--seg[t1][t2]==0) cum[t1][v]--, ans-=(ll)((1<<(n-mp[v]-1))-cum[!t1][v]);}
update(t1,(t2^v)|(v<<1),val);
}
int main(){
scanf("%d%d",&n,&q);
for(int i=0;i<n;i++) mp[1<<i]=i;
for(int i=0;i<q;i++){
int t1,t2;
scanf("%d%d",&t1,&t2);
dist[t1][t2]=!dist[t1][t2],dist[t1][t2-1]=!dist[t1][t2-1];
update(t1,t2,dist[t1][t2]); update(t1,t2-1,dist[t1][t2-1]);
printf("%lld\n",ans*4ll+1ll);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |