제출 #40908

#제출 시각아이디문제언어결과실행 시간메모리
40908HassoonyPoklon (COCI17_poklon)C++14
0 / 140
364 ms43088 KiB
#include<bits/stdc++.h> #include<unordered_map> using namespace std; typedef long long ll; typedef double D; const ll inf=(1ll<<61); const int mod=1e9+7; const int MX=5e5+9; const int SQ=200; int n,q,a[MX],ans,res[MX]; pair<int,pair<int,int> >Q[MX]; unordered_map<int,int>cnt; bool cmp(pair<int,pair<int,int> >A,pair<int,pair<int,int> >B){ if((A.first/SQ)==(B.first/SQ)){ return A.second.first<B.second.first; } return (A.first/SQ)<(B.first/SQ); } void add(int x){ ans-=(cnt[x]==2); cnt[x]++; ans+=(cnt[x]==2); } void rem(int x){ ans-=(cnt[x]==2); cnt[x]--; ans+=(cnt[x]==2); } int main(){ cin>>n>>q; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=0;i<q;i++){ scanf("%d%d",&Q[i].first,&Q[i].second.first); Q[i].second.second=i; } sort(Q,Q+q,cmp); int mol=1,mor=0; for(int i=0;i<q;i++){ int L=Q[i].first,R=Q[i].second.first; while(mor<R){ add(a[++mor]); } while(mor>R){ rem(a[mor++]); } while(mol<L){ rem(a[mol++]); } while(mol>L){ add(a[++mol]); } // cout<<L<<" "<<R<<" "<<Q[i].second.second<<endl; res[Q[i].second.second]=ans; } for(int i=0;i<q;i++)printf("%d\n",res[i]); }

컴파일 시 표준 에러 (stderr) 메시지

poklon.cpp: In function 'int main()':
poklon.cpp:32:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
poklon.cpp:35:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&Q[i].first,&Q[i].second.first);
                                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...