Submission #471528

#TimeUsernameProblemLanguageResultExecution timeMemory
471528jazzupPilot (NOI19_pilot)C++14
40 / 100
85 ms15512 KiB
#include<cstdio> #include<algorithm> #include<set> #include<vector> using namespace std; long long ans[1000007]; pair<int,int> a[1000007]; set<int> b; int main(){ int n,q,y; set<int>::iterator it; scanf("%d%d",&n,&q); for(int i=0;i<n;i++){ scanf("%d",&a[i].first); a[i].second=i+1; } sort(a,a+n,greater<pair<int,int> >()); long long cur= (n*(n-1))/2 + n; int idx=0; 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); int r=*it; it--; int l=*it; int 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==n){ break; } } if(idx==n)break; ans[i]=cur; } for(int i=0;i<q;i++){ scanf("%d",&y); printf("%lld\n",ans[y]); } return 0; }

Compilation message (stderr)

pilot.cpp: In function 'int main()':
pilot.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
pilot.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d",&a[i].first);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
pilot.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d",&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...