Submission #371002

#TimeUsernameProblemLanguageResultExecution timeMemory
371002FatihSolakPoklon (COCI17_poklon)C++17
0 / 140
4 ms364 KiB
#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 (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   25 |  freopen("in.txt","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
poklon.cpp:26:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  freopen("out.txt","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...