Submission #1007702

#TimeUsernameProblemLanguageResultExecution timeMemory
1007702phongFire (JOI20_ho_t5)C++17
1 / 100
237 ms98120 KiB
#include<bits/stdc++.h> #define ll long long #define int long long const int nmax = 2e5 + 5, N = 6e5 + 1; const ll oo = 1e9; const int lg = 7, M = 4e3; const int base = 2e5, mod = 998244353; #define pii pair<ll, ll> #define fi first #define se second #define endl "\n" #define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';cout << endl using namespace std; int n, q, a[nmax]; namespace sub1{ int rmq[nmax][lg + 1]; int get(int l, int r){ int k = __lg(r - l + 1); return max(rmq[l][k], rmq[r - (1 << k) + 1][k]); } void sol(){ for(int i = 1; i <= n; ++i) rmq[i][0] = a[i]; for(int j = 1; j <= lg; ++j){ for(int i = 1; i + (1 << j) -1 <= n; ++i){ rmq[i][j] = max(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]); } } while(q--){ int t, l, r; cin >> t >> l >> r; ll ans = 0; for(int i = l; i <= r; ++i){ ans += get(max(i - t, 1ll), i); } cout << ans << endl; } } } namespace sub2{ int L[nmax], R[nmax]; struct node{ int l, i, r, id; }; struct F1{ ll f[nmax * 3]; void update(int x, int val){ x += 2 * n + 1; for(; x; x -= x&-x) f[x] += val; } ll get(int x){ ll res = 0; x += 2 * n + 1; for(; x <= N;x += x&-x) res += f[x]; return res; } }A[2], B[2], C[2],G[2]; struct F2{ ll f[nmax * 3]; void update(int x, int val){ x += 2 * n + 1; for(; x <= N; x += x&-x) f[x] += val; } ll get(int x){ ll res = 0; x += 2 * n + 1; for(; x;x -= x&-x) res += f[x]; return res; } }D[2], E[2]; vector<node> adj[nmax]; vector<pii> Q[nmax]; int ans[nmax]; void sol(){ for(int i = 1; i <= n; ++i){ L[i] = i - 1; while(L[i] > 0 && a[L[i]] < a[i]) L[i] = L[L[i]]; } for(int i = n; i >= 1; --i){ R[i]= i + 1; while(R[i] <= n && a[R[i]] <= a[i]) R[i] = R[R[i]]; } for(int i = 1; i <= n; ++i){ L[i]++;R[i]--; if(L[i] == 1) L[i] = -n; adj[i].push_back({L[i], i, R[i], 0}); adj[R[i]].push_back({L[i], i, R[i], 1}); } for(int e = 1; e <= q; ++e){ int t, l, r; cin >> t >> l >> r; Q[r].push_back({t, e}); Q[l - 1].push_back({t, -e}); } for(int x = 1; x <= n; ++x){ for(auto [l, i, r, id] : adj[x]){ if(id == 0){ D[0].update(l - 1, (l - 1) * a[i]); D[1].update(l - 1, a[i]); E[0].update(i, i * a[i]); E[1].update(i, a[i]); G[0].update(i - l, (i - l) * a[i]); G[1].update(i - l, a[i]); } else{ D[0].update(l - 1, -(l - 1) * a[i]); D[1].update(l - 1, -a[i]); E[0].update(i, -i * a[i]); E[1].update(i, -a[i]); G[0].update(i - l, -(i - l) * a[i]); G[1].update(i - l, -a[i]); // A[0].update(r - l + 1, (r - l + 1) * a[i]); A[1].update(r - l + 1, a[i]); B[0].update(i - l, (i - l) * a[i]); B[1].update(i - l, a[i]); C[0].update(r - i, (r - i) * a[i]); C[1].update(r - i, a[i]); } } for(auto [t, idx] : Q[x]){ int id = abs(idx); int p; if(idx > 0) p = 1; else p = -1; int val = 0; // t = min(t, x); val += A[0].get(t) - A[1].get(t) * t; val -= B[0].get(t) - B[1].get(t) * t; val -= C[0].get(t) - C[1].get(t) * t; // val += D[1].get(x - t) * (x - t) - D[0].get(x - t); val -= E[1].get(x - t) * (x - t) - E[0].get(x - t); val -= G[0].get(t) - G[1].get(t) * t; // cout << x << ' ' << val << ' ' << p << endl; ans[id] += val * p; } } for(int i = 1; i <= q; ++i) cout << ans[i] << endl; } } main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // freopen("code.inp", "r", stdin); // freopen("code.out", "w", stdout); cin >> n >> q; for(int i = 1; i <= n; ++i) cin >> a[i]; sub2::sol(); } /* 3 1 4 1 1 5 2 2 */

Compilation message (stderr)

ho_t5.cpp:149:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  149 | main(){
      | ^~~~
#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...