Submission #231045

#TimeUsernameProblemLanguageResultExecution timeMemory
231045JooDdae역사적 조사 (JOI14_historical)C++17
25 / 100
4008 ms14456 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll sz = 100000000; char in_buf[sz]; char out_buf[sz]; inline char read_next() { static ll i = sz; if (i == sz) { fread(in_buf, 1, sz, stdin); i = 0; } return in_buf[i++]; } inline ll read_int() { ll r = read_next() - '0'; char ch; while ((ch = read_next()) >= '0' && ch <= '9') r = r * 10 + ch - '0'; return r; } ll w_idx; inline void write_next(char ch) { if (w_idx == sz) { fwrite(out_buf, 1, sz, stdout); w_idx = 0; } out_buf[w_idx++] = ch; } inline void write_int(ll x) { char s[10]; ll i = 0; do { s[i++] = x % 10; x /= 10; } while (x > 0); i--; while (i >= 0) write_next(s[i--] + '0'); } #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(){ n = read_int(); m = read_int(); for(int i=1;i<=n;i++) x[i] = read_int(), mp[x[i]] = 0; for(auto &x : mp) x.second = ++cnt; for(int i=1;i<=m;i++) q[i].l = read_int(), q[i].r = read_int(), 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++){write_int(ans[i]); write_next('\n');} fwrite(out_buf, 1, w_idx, stdout); }

Compilation message (stderr)

historic.cpp: In function 'char read_next()':
historic.cpp:16:14: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fread(in_buf, 1, sz, stdin);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...