Submission #201670

#TimeUsernameProblemLanguageResultExecution timeMemory
201670SamAndPoklon (COCI17_poklon)C++17
140 / 140
1537 ms18416 KiB
#include <bits/stdc++.h> using namespace std; const int N = 500005; int s; struct ban { int i; int l, r; }; bool operator<(const ban& a, const ban& b) { if ((a.l / s) < (b.l / s)) return true; if ((a.l / s) > (b.l / s)) return false; if ((a.l / s) % 2) return a.r < b.r; return a.r > b.r; } int n, m; int a[N]; ban b[N]; int yans; int q[N]; void ave(int x) { if (q[x] == 2) --yans; ++q[x]; if (q[x] == 2) ++yans; } void han(int x) { if (q[x] == 2) --yans; --q[x]; if (q[x] == 2) ++yans; } int ans[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); int z = 0; vector<int> v; map<int, int> mp; for (int i = 1; i <= n; ++i) v.push_back(a[i]); sort(v.begin(), v.end()); for (int i = 0; i < n; ++i) { if (!i || v[i] != v[i - 1]) mp[v[i]] = ++z; } for (int i = 1; i <= n; ++i) a[i] = mp[a[i]]; for (int i = 1; i <= m; ++i) { scanf("%d%d", &b[i].l, &b[i].r); b[i].i = i; } s = sqrt(n); sort(b + 1, b + m + 1); int l = 1, r = 0; for (int i = 1; i <= m; ++i) { int ll = b[i].l, rr = b[i].r; while (r < rr) { ++r; ave(a[r]); } while (l > ll) { --l; ave(a[l]); } while (r > rr) { han(a[r]); --r; } while (l < ll) { han(a[l]); ++l; } ans[b[i].i] = yans; } for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]); return 0; }

Compilation message (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
poklon.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
poklon.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &b[i].l, &b[i].r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...