Submission #477771

#TimeUsernameProblemLanguageResultExecution timeMemory
477771NeosPoklon (COCI17_poklon)C++14
140 / 140
526 ms36284 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<ll, ll> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vii> vvii; #define task "test" #define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ ) #define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- ) #define sz(x) (int)x.size() #define fi first #define se second #define all(x) x.begin(), x.end() #define numBit(x) __builtin_popcount(x) #define lb lower_bound #define ub upper_bound #define ar array #define endl '\n' const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; const int N = 5e5 + 7; const ll inf = 0x3f3f3f3f; int n, q, a[N], prv[N], pos[N], bit[N], ans[N]; vi tmp; vii event[N]; void upd(int p, int v) { if (p == 0) return; for (; p < N; p += p & -p) bit[p] += v; } int get(int p) { int ans = 0; for (; p > 0; p -= p & -p) ans += bit[p]; return ans; } int main() { // fastIO; scanf("%d %d", &n, &q); forw(i, 1, n + 1) scanf("%d", &a[i]), tmp.push_back(a[i]); sort(all(tmp)); tmp.resize(unique(all(tmp)) - tmp.begin()); forw(i, 1, n + 1) a[i] = lb(all(tmp), a[i]) - tmp.begin(); for (int i = 1, l, r; i <= q; i++) { scanf("%d %d", &l, &r); event[r].push_back(ii(l, i)); } forw(i, 1, n + 1) { prv[i] = pos[a[i]]; pos[a[i]] = i; if (prv[i] != prv[prv[i]]) { if (prv[prv[prv[i]]] != prv[prv[i]]) { upd(prv[prv[prv[i]]], 1); upd(prv[prv[i]], -1); } upd(prv[prv[i]], -1); upd(prv[i], 1); } for (auto it: event[i]) ans[it.se] = get(i) - get(it.fi - 1); } forw(i, 1, q + 1) printf("%d\n", ans[i]); } /* 3 5 5 4 3 1 2 3 0 0 3 */

Compilation message (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   scanf("%d %d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~~
poklon.cpp:57:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   forw(i, 1, n + 1) scanf("%d", &a[i]), tmp.push_back(a[i]);
      |                     ~~~~~^~~~~~~~~~~~~
poklon.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d %d", &l, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...