Submission #471529

#TimeUsernameProblemLanguageResultExecution timeMemory
471529jazzupPilot (NOI19_pilot)C++14
89 / 100
1084 ms75304 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<long long,long long> a[1000007]; set<long long> b; int main(){ long long n,q,y; set<long long>::iterator it; scanf("%lld%lld",&n,&q); for(long long i=0;i<n;i++){ scanf("%lld",&a[i].first); a[i].second=i+1; } sort(a,a+n,greater<pair<long long,long long> >()); long long cur= (n*(n-1))/2 + n; long long idx=0; b.insert(0); b.insert(n+1); for(long long 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==n){ break; } } if(idx==n)break; ans[i]=cur; } for(long long 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:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%lld%lld",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
pilot.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%lld",&a[i].first);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
pilot.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   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...