Submission #471830

#TimeUsernameProblemLanguageResultExecution timeMemory
471830jazzupPilot (NOI19_pilot)C++14
89 / 100
1092 ms104916 KiB
/*input 6 3 1 3 2 4 1 2 2 3 4 */ //NOI-SG 2019 #include<cstdio> #include<algorithm> #include<set> #include<vector> using namespace std; long long ans[1000007]; pair<int,int> a[1000007]; set<int> b; vector<int> v[1000007]; int main(){ long long n,q,y; set<int>::iterator it; int sc; scanf("%lld%lld",&n,&q); for(int i=0;i<n;i++){ scanf("%d",&sc); v[sc].push_back(i+1); } int cnt=0; for(int i=1;i<=1000000;i++){ for(int j=0;j<v[i].size();j++){ a[cnt].first=i; a[cnt].second=v[i][j]; cnt++; } } long long cur= (n*(n-1))/2 + n; int idx=n-1; b.insert(0); b.insert(n+1); for(int i=1000000;i>0;i--){ while(i<a[idx].first){ it=b.lower_bound(a[idx].second); long long r=*it; it--; long long l=*it; long long diff=r-l-1; cur-=((diff*(diff-1))/2 + diff); diff=r-a[idx].second-1; cur+=((diff*(diff-1))/2 + diff); diff=a[idx].second-l-1; cur+=((diff*(diff-1))/2 + diff); b.insert(a[idx].second); idx--; if(idx<0){ break; } } if(idx<0)break; ans[i]=cur; } for(int i=0;i<q;i++){ scanf("%lld",&y); printf("%lld\n",ans[y]); } return 0; }

Compilation message (stderr)

pilot.cpp: In function 'int main()':
pilot.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(int j=0;j<v[i].size();j++){
      |               ~^~~~~~~~~~~~
pilot.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%lld%lld",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
pilot.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%d",&sc);
      |   ~~~~~^~~~~~~~~~
pilot.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%lld",&y);
      |   ~~~~~^~~~~~~~~~~
#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...