Submission #44779

#TimeUsernameProblemLanguageResultExecution timeMemory
44779evpipisPoklon (COCI17_poklon)C++11
140 / 140
2074 ms36092 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second typedef pair<int, int> ii; const int len = 5e5+5; int arr[len], ans, k, cnt[len]; pair<int, ii> ask[len]; map<int, int> mymap; bool comp(pair<int, ii> a, pair<int, ii> b){ if (a.se.fi/k < b.se.fi/k) return true; if (a.se.fi/k > b.se.fi/k) return false; return (a.se.se < b.se.se); } void add(int i, int x){ if (cnt[arr[i]] == 2) ans--; cnt[arr[i]] += x; if (cnt[arr[i]] == 2) ans++; } int main(){ int n, q, cur = 0, temp; scanf("%d %d", &n, &q); k = sqrt(n); for (int i = 0; i < n; i++){ scanf("%d", &temp); if (!mymap.count(temp)) arr[i] = mymap[temp] = cur++; else arr[i] = mymap[temp]; } for (int i = 0; i < q; i++){ scanf("%d %d", &ask[i].se.fi, &ask[i].se.se); ask[i].se.fi--, ask[i].se.se--; ask[i].fi = i; } sort(ask, ask+q, comp); int l = 0, r = -1; for (int i = 0; i < q; i++){ while (r < ask[i].se.se) r++, add(r, 1); while (r > ask[i].se.se) add(r, -1), r--; while (l < ask[i].se.fi) add(l, -1), l++; while (l > ask[i].se.fi) l--, add(l, 1); ask[i].se.fi = ans; } sort(ask, ask+q); for (int i = 0; i < q; i++) printf("%d\n", ask[i].se.fi); return 0; }

Compilation message (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
poklon.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &temp);
         ~~~~~^~~~~~~~~~~~~
poklon.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &ask[i].se.fi, &ask[i].se.se);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...