Submission #239820

#TimeUsernameProblemLanguageResultExecution timeMemory
239820mhy908Pilot (NOI19_pilot)C++14
100 / 100
990 ms72312 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define eb emplace_back using namespace std; typedef long long LL; int n, q; vector<int> vc[1000010]; LL ans[1000010], nans, tmp, sz[1000010]; bool ch[1000010]; int par[1000010]; int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);} void mergepar(int a, int b){ a=findpar(a); b=findpar(b); if(a==b)return; nans-=sz[a]*(sz[a]+1)/2; nans-=sz[b]*(sz[b]+1)/2; sz[a]+=sz[b]; par[b]=a; nans+=sz[a]*(sz[a]+1)/2; } int main(){ scanf("%d %d", &n, &q); for(int i=1; i<=1000000; i++)par[i]=i, sz[i]=1; nans=(LL)n; tmp=(LL)n; for(int i=1; i<=n; i++){ int a; scanf("%d", &a); vc[a].eb(i); } for(int i=1; i<=1000000; i++){ for(auto j:vc[i]){ ch[j]=true; if(ch[j+1])mergepar(j, j+1); if(ch[j-1])mergepar(j-1, j); tmp--; } ans[i]=nans-tmp; } for(int i=1; i<=q; i++){ int a; scanf("%d", &a); printf("%lld\n", ans[a]); } }

Compilation message (stderr)

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