Submission #74606

#TimeUsernameProblemLanguageResultExecution timeMemory
74606cubecube1000즐거운 사진 수집 (JOI13_collecting)C++14
100 / 100
1643 ms239848 KiB
#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)

collecting.cpp: In function 'int main()':
collecting.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&q);
     ~~~~~^~~~~~~~~~~~~~
collecting.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&t1,&t2);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...