Submission #996278

#TimeUsernameProblemLanguageResultExecution timeMemory
996278vladilius역사적 조사 (JOI14_historical)C++17
100 / 100
1755 ms22892 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define ins insert struct ST{ vector<ll> t; int n; ST(int ns){ n = ns; t.resize(4 * n); } void upd(int v, int tl, int tr, int& p, int& k){ if (tl == tr){ t[v] += k; return; } int tm = (tl + tr) / 2, vv = 2 * v; if (p <= tm){ upd(vv, tl, tm, p, k); } else { upd(vv + 1, tm + 1, tr, p, k); } t[v] = max(t[vv], t[vv + 1]); } void upd(int p, int k){ upd(1, 1, n, p, k); } ll get(int v, int tl, int tr, int& l, int& r){ if (l > tr || r < tl) return 0; if (l <= tl && tr <= r) return t[v]; int tm = (tl + tr) / 2, vv = 2 * v; return max(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r)); } ll get(int l, int r){ return get(1, 1, n, l, r); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin>>n>>q; vector<int> a(n + 1); map<int, vector<int>> p; for (int i = 1; i <= n; i++){ cin>>a[i]; p[a[i]].pb(i); } const int S = sqrt(n); vector<int> x; for (auto f: p){ if (f.ss.size() > S){ x.pb(f.ff); } } vector<pii> end[n + 1]; for (int i = 1; i <= q; i++){ int l, r; cin>>l>>r; end[r].pb({l, i}); } vector<int> :: iterator it1, it2; auto count = [&](int l, int r, int x){ it1 = lower_bound(p[x].begin(), p[x].end(), l); it2 = upper_bound(p[x].begin(), p[x].end(), r); return (it2 - it1); }; ST T(n); vector<ll> out(q + 1); for (int i = 1; i <= n; i++){ if (p[a[i]].size() <= S){ for (int j: p[a[i]]){ T.upd(j, a[i]); if (j == i) break; } } for (auto [l, j]: end[i]){ out[j] = T.get(l, i); for (int f: x){ out[j] = max(out[j], 1LL * f * count(l, i, f)); } } } for (int i = 1; i <= q; i++){ cout<<out[i]<<"\n"; } }

Compilation message (stderr)

historic.cpp: In function 'int main()':
historic.cpp:60:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   60 |         if (f.ss.size() > S){
      |             ~~~~~~~~~~~~^~~
historic.cpp:80:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   80 |         if (p[a[i]].size() <= S){
      |             ~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...