Submission #145790

#TimeUsernameProblemLanguageResultExecution timeMemory
145790maruii역사적 조사 (JOI14_historical)C++14
40 / 100
4005 ms9312 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define ff first #define ss second #define eack emplace_back #define all(x) (x).begin(), (x).end() int X[100005], in[100005][2]; vector<int> xx; const int SIZE = 1 << 17; struct ST { long long A[2 * SIZE]; int sz; void update(int nn, int ns, int ne, int x, int v) { if (ns > x || ne < x) return; if (x <= ns && ne <= x) { A[nn] += v; return; } int m = ns + ne >> 1; update(nn << 1, ns, m, x, v); update(nn << 1 | 1, m + 1, ne, x, v); A[nn] = max(A[nn << 1], A[nn << 1 | 1]); } void update(int x, int v) { update(1, 0, sz, x, v); } long long query() { return A[1]; } } seg; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int N, Q; cin >> N >> Q; for (int i = 1; i <= N; ++i) cin >> X[i], xx.eack(X[i]); sort(all(xx)); xx.erase(unique(all(xx)), xx.end()); for (int i = 1; i <= N; ++i) { X[i] = lower_bound(all(xx), X[i]) - xx.begin(); } seg.sz = xx.size() - 1; vector<pair<pii, int> > qry(Q); vector<long long> ans(Q); for (int i = 0; i < Q; ++i) { cin >> in[i][0] >> in[i][1]; qry.eack(pii(in[i][0] / 600, in[i][1]), i); } sort(all(qry)); int s = 1, e = 0; for (auto i : qry) { int ns = in[i.ss][0], ne = in[i.ss][1]; for (; s < ns; ++s) seg.update(X[s], -xx[X[s]]); for (; s > ns; --s) seg.update(X[s - 1], xx[X[s - 1]]); for (; e < ne; ++e) seg.update(X[e + 1], xx[X[e + 1]]); for (; e > ne; --e) seg.update(X[e], -xx[X[e]]); ans[i.ss] = seg.query(); } for (auto i : ans) cout << i << '\n'; return 0; }

Compilation message (stderr)

historic.cpp: In member function 'void ST::update(int, int, int, int, int)':
historic.cpp:22:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = ns + ne >> 1;
           ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...