Submission #261039

#TimeUsernameProblemLanguageResultExecution timeMemory
261039onjo0127역사적 조사 (JOI14_historical)C++11
100 / 100
316 ms8048 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int bck = 320; struct query { int s, e, id; }; int N, X[100009], I[100009]; long long ans[100009], sum[100009], mx; vector<query> L[333]; void add(int x) { sum[I[x]] += X[x]; mx = max(mx, sum[I[x]]); } void del(int x) { sum[I[x]] -= X[x]; } int main() { vector<int> P; int Q; scanf("%d%d", &N, &Q); for(int i=1; i<=N; i++) { scanf("%d", &X[i]); P.push_back(X[i]); } sort(P.begin(), P.end()); P.resize(unique(P.begin(), P.end()) - P.begin()); for(int i=1; i<=N; i++) I[i] = lower_bound(P.begin(), P.end(), X[i]) - P.begin() + 1; for(int i=1; i<=Q; i++) { int s, e; scanf("%d%d", &s, &e); L[s / bck].push_back({s, e, i}); } for(int i=0; i<=N/bck; i++) sort(L[i].begin(), L[i].end(), [&](query PP, query QQ) { return PP.e < QQ.e; }); for(int i=0; i<=N/bck; i++) { mx = 0; int ql = i*bck, qr = min((i+1)*bck - 1, N), rm = qr; for(auto& it: L[i]) { int s = it.s, e = it.e; if(s/bck == e/bck) { mx = 0; for(int i=s; i<=e; i++) add(i); ans[it.id] = mx; for(int i=s; i<=e; i++) del(i); mx = 0; } else { while(rm < e) add(++rm); long long tmp = mx; for(int i=s; i<=qr; i++) add(i); ans[it.id] = mx; for(int i=s; i<=qr; i++) del(i); mx = tmp; } } for(int i=rm; i>qr; i--) del(i); } for(int i=1; i<=Q; i++) printf("%lld\n", ans[i]); return 0; }

Compilation message (stderr)

historic.cpp: In function 'int main()':
historic.cpp:41:7: warning: unused variable 'ql' [-Wunused-variable]
   int ql = i*bck, qr = min((i+1)*bck - 1, N), rm = qr;
       ^~
historic.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int Q; scanf("%d%d", &N, &Q);
         ~~~~~^~~~~~~~~~~~~~~~
historic.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &X[i]);
   ~~~~~^~~~~~~~~~~~~
historic.cpp:34:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int s, e; scanf("%d%d", &s, &e);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...