Submission #552331

#TimeUsernameProblemLanguageResultExecution timeMemory
552331Tien_NoobPoklon (COCI17_poklon)C++17
140 / 140
639 ms37448 KiB
//Make CSP great again //You're as beautiful as the day I lost you #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 5e5; int n, q, a[N + 1], res[N + 1]; struct FenwickTree { int Tree[N + 1]; void add(int pos, int val) { if (pos == 0) { return ; } for (; pos <= n; pos += pos & (-pos)) { Tree[pos] += val; } } int sum(int pos) { int ret = 0; for (; pos > 0; pos -= pos & (-pos)) { ret += Tree[pos]; } return ret; } int sum(int l, int r) { return sum(r) - sum(l - 1); } } Tree; vector<pair<int, int> > Query[N + 1]; map<int, int> Map[3]; void read() { cin >> n >> q; for (int i = 1; i <= n; ++ i) { cin >> a[i]; } for (int i = 1; i <= q; ++ i) { int l, r; cin >> l >> r; Query[r].push_back(make_pair(i, l)); } } void solve() { for (int i = 1; i <= n; ++ i) { Tree.add(Map[2][a[i]], 1); Map[2][a[i]] = Map[1][a[i]]; Tree.add(Map[2][a[i]], -2); Map[1][a[i]] = Map[0][a[i]]; Tree.add(Map[1][a[i]], 1); Map[0][a[i]] = i; for (auto x : Query[i]) { res[x.first] = Tree.sum(x.second, i); } } for (int i = 1; i <= q; ++ i) { cout << res[i] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

Compilation message (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...