# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371002 | 2021-02-25T13:26:28 Z | FatihSolak | Poklon (COCI17_poklon) | C++17 | 4 ms | 364 KB |
#include <bits/stdc++.h> #define N 500005 using namespace std; int arr[N]; int ans[N]; int cnt[N]; map<int,int> mp; int block = 700; bool comp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){ if(a.first.first/block == b.first.first/block){ return a.first.second < b.first.second; } return a.first.first/block < b.first.first/block; } int t; int sum; void upd(int pos,int val){ sum -= (cnt[arr[pos]] == 2); cnt[arr[pos]] += val; sum += (cnt[arr[pos]] == 2); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); int n,q; cin >> n >> q; for(int i=1;i<=n;i++){ int a; cin >> a; if(!mp[a])mp[a] = ++t; arr[i] = mp[a]; } vector<pair<pair<int,int>,int>> query; for(int i=0;i<q;i++){ int l,r; cin >> l >> r; query.push_back({{l,r},i}); } sort(query.begin(), query.end(),comp); int l = 0,r = -1; for(auto u: query){ int lq = u.first.first; int rq = u.first.second; while(l > lq){ upd(--l,1); } while(r < rq){ upd(++r,1); } while(l < lq){ upd(l++,-1); } while(r > rq){ upd(r--,-1); } ans[u.second] = sum; } for(int i=0;i<q;i++){ cout << ans[i] << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Incorrect | 2 ms | 364 KB | Output isn't correct |
3 | Incorrect | 2 ms | 364 KB | Output isn't correct |
4 | Incorrect | 2 ms | 364 KB | Output isn't correct |
5 | Incorrect | 2 ms | 364 KB | Output isn't correct |
6 | Incorrect | 2 ms | 364 KB | Output isn't correct |
7 | Incorrect | 4 ms | 364 KB | Output isn't correct |
8 | Incorrect | 4 ms | 364 KB | Output isn't correct |
9 | Incorrect | 2 ms | 364 KB | Output isn't correct |
10 | Incorrect | 2 ms | 364 KB | Output isn't correct |