제출 #481027

#제출 시각아이디문제언어결과실행 시간메모리
481027LptN21Poklon (COCI17_poklon)C++14
140 / 140
696 ms34776 KiB
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define PI acos(-1.0) #define FF first #define SS second #define eps 1e-9 // vector #define pb push_back #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define lb lower_bound #define ub upper_bound // bit #define CNTBIT(x) __builtin_popcount(x) #define ODDBIT(x) __builtin_parity(x) #define MASK(i) (1ll<<(i)) #define BIT(x, i) (((x)>>(i))&1) #define SUBSET(big, small) (((big)&(small))==(small)) #define MINBIT(x) (x)&(-x) // typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, int> ii; typedef pair<int, ii> i3; /* CODE BELOW */ const int N=500000+7, M=447; // M=SQRT(N) ~ 447 + const const int MOD=1e9+7; const ll oo=1e18+9; int n, m, k, t; int fen[N]; void upd(int i, int v) { if(!i) return; for(;i<=n;i+=i&-i) fen[i]+=v; } int get(int i) { int res=0; for(;i>0;i-=i&-i) res+=fen[i]; return res; } int qry(int l, int r) { return get(r)-get(l-1); } int ans[N], a[N]; map<int, vector<int> > lst; map<int, int> cnt; vector<ii> q[N]; signed main() { //freopen("test.INP", "r", stdin); //freopen("test.OUT", "w", stdout); //fastIO; scanf("%d%d", &n, &m); int l, r; for(int i=1;i<=n;i++) scanf("%d", &a[i]); const int SUB1=3000; if(max(n, m)<=SUB1) { for(int i=1;i<=m;i++) { scanf("%d%d", &l, &r); map<int, int> _cnt; int _ans=0; for(int j=l;j<=r;j++) _cnt[a[j]]++; for(auto it=_cnt.begin();it!=_cnt.end();it++) if(it->SS==2) _ans++; printf("%d\n", _ans); } return 0; } for(int i=1;i<=m;i++) { scanf("%d%d", &l, &r); q[r].pb(ii(l, i)); } for(int i=1;i<=n;i++) { cnt[a[i]]++; if(cnt[a[i]]>1) { int lsz=sz(lst[a[i]]); upd(lst[a[i]][lsz-1], 1); upd(lst[a[i]][lsz-2], -2); if(lsz>2) upd(lst[a[i]][lsz-3], 1); } else lst[a[i]].pb(0); for(ii qr:q[i]) { tie(l, r)=qr; ans[r]=qry(l, i); } lst[a[i]].pb(i); } for(int i=1;i<=m;i++) printf("%d\n", ans[i]); return 0; } /* stuff you should look for - int overflow, array bounds - special/edge cases (n=1?) - do smth instead of nothing and stay organized - WRITE STUFF DOWN - DONT JUST STICK ON ONE APPROACH */

컴파일 시 표준 에러 (stderr) 메시지

poklon.cpp: In function 'int main()':
poklon.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d%d", &n, &m); int l, r;
      |     ~~~~~^~~~~~~~~~~~~~~~
poklon.cpp:59:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     for(int i=1;i<=n;i++) scanf("%d", &a[i]);
      |                           ~~~~~^~~~~~~~~~~~~
poklon.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |             scanf("%d%d", &l, &r);
      |             ~~~~~^~~~~~~~~~~~~~~~
poklon.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         scanf("%d%d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...