Submission #1101122

#TimeUsernameProblemLanguageResultExecution timeMemory
1101122InvMODPoklon (COCI17_poklon)C++14
140 / 140
1035 ms39356 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;} const int N = 5e5+5; const ll MOD = 1e9+7; const ll INF = 1e18; const int SZ = 750; struct Query{ int l,r,id; }; int a[N], ans[N], mp[N], cnt[N], res = 0; Query Q[N]; vector<int> tmp; void add(int x){ if(cnt[mp[x]] == 2) res--; cnt[mp[x]]++; if(cnt[mp[x]] == 2) res++; return; } void rem(int x){ if(cnt[mp[x]] == 2) res--; cnt[mp[x]]--; if(cnt[mp[x]] == 2) res++; return; } void solve() { int n,q; cin >> n >> q; FOR(i, 1, n){ cin >> a[i]; tmp.pb(a[i]); } tmp.pb(0); sort(all(tmp)); tmp.erase(unique(all(tmp)), tmp.end()); FOR(i, 0, n){ int p = lower_bound(all(tmp), a[i]) - tmp.begin(); mp[i] = p; } FOR(i, 1, q){ cin >> Q[i].l >> Q[i].r; Q[i].id = i; } sort(1 + Q, 1+q+Q, [&](Query x, Query y){ if(x.l/SZ != y.l/SZ) return x.l < y.l; else return ((x.l/SZ)&1 ? (x.r < y.r) : (x.r > y.r)); }); res = 0; int cl = 0, cr = 0; add(0); FOR(i, 1, q){ while(cr < Q[i].r) add(++cr); while(cl < Q[i].l) rem(cl++); while(cr > Q[i].r) rem(cr--); while(cl > Q[i].l) add(--cl); ans[Q[i].id] = res; } FOR(i, 1, q) cout << ans[i] <<"\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

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