제출 #231035

#제출 시각아이디문제언어결과실행 시간메모리
231035JooDdae역사적 조사 (JOI14_historical)C++17
40 / 100
4074 ms13688 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define mid ((l+r)>>1) struct query{ int l, r, id; bool operator < (const query &o) const{ return make_pair(l>>9, r) < make_pair(o.l>>9, o.r); } }q[100100]; int n, m, cnt; ll x[100100], tree[400400], ans[100100]; map<ll, int> mp; void update(int id, ll val, int node = 1, int l = 1, int r = cnt){ if(id < l || r < id) return; if(l == r){ tree[node] += val; return; } update(id, val, node*2, l, mid), update(id, val, node*2+1, mid+1, r); tree[node] = max(tree[node*2], tree[node*2+1]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin >> n >> m; for(int i=1;i<=n;i++) cin >> x[i], mp[x[i]] = 0; for(auto &x : mp) x.second = ++cnt; for(int i=1;i<=m;i++) cin >> q[i].l >> q[i].r, q[i].id = i; sort(q+1, q+1+m); int l = 1, r = 0; for(int i=1;i<=m;i++){ while(l > q[i].l) l--, update(mp[x[l]], x[l]); while(r < q[i].r) r++, update(mp[x[r]], x[r]); while(l < q[i].l) update(mp[x[l]], -x[l]), l++; while(r > q[i].r) update(mp[x[r]], -x[r]), r--; ans[q[i].id] = tree[1]; } for(int i=1;i<=m;i++) cout << ans[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...