Submission #42321

#TimeUsernameProblemLanguageResultExecution timeMemory
42321minkank역사적 조사 (JOI14_historical)C++14
100 / 100
249 ms66044 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; #define st first #define nd second typedef pair<int, int> ii; ii qu[N]; int n, m, a[N], Time, b[N]; long long ans[N]; vector<int> Q[N]; map<int, int> sax; int cnt[N], cnt2[N]; bool cmp(int a, int b) { return qu[a].nd < qu[b].nd; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 1; i <= n; ++i) { cin >> a[i]; if(!sax[a[i]]) sax[a[i]] = ++Time; b[i] = sax[a[i]]; } for(int i = 1; i <= m; ++i) cin >> qu[i].st >> qu[i].nd, Q[(long long)(qu[i].st / sqrt(n))].push_back(i); for(int i = 0; i <= sqrt(n); ++i) { sort(Q[i].begin(), Q[i].end(), cmp); int maxL = 0; for(int j = 0; j < Q[i].size(); ++j) maxL = max(maxL, qu[Q[i][j]].st); int cur = maxL; long long curmx = 0; memset(cnt, 0, sizeof cnt); for(int j = 0; j < Q[i].size(); ++j) { int id = Q[i][j], L = qu[id].st, R = qu[id].nd; while(cur <= R) { int x = a[cur]; cnt[b[cur]]++; curmx = max(curmx, 1LL * cnt[b[cur]] * x); cur++; } ans[id] = curmx; for(int k = L; k < min(maxL, R + 1); ++k) { int x = a[k]; cnt2[b[k]]++; ans[id] = max(ans[id], 1LL * (cnt2[b[k]] + cnt[b[k]]) * x); } for(int k = L; k < min(maxL, R + 1); ++k) { int x = a[k]; cnt2[b[k]]--; } } } for(int i = 1; i <= m; ++i) printf("%lld\n", ans[i]); }

Compilation message (stderr)

historic.cpp: In function 'int main()':
historic.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < Q[i].size(); ++j) maxL = max(maxL, qu[Q[i][j]].st);
                    ^
historic.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < Q[i].size(); ++j) {
                    ^
historic.cpp:49:9: warning: unused variable 'x' [-Wunused-variable]
     int x = a[k];
         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...