제출 #959536

#제출 시각아이디문제언어결과실행 시간메모리
959536AndreiBOTOArranging Shoes (IOI19_shoes)C++14
100 / 100
207 ms275284 KiB
#include <bits/stdc++.h> #pragma optimize GCC ("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") ///#include <tryhardmode> ///#include <GODMODE::ON> using namespace std; const int NMAX=2e5+5; queue<int>right_shoe[NMAX]; queue<int>left_shoe[NMAX]; bool viz[NMAX]; int aib[NMAX]; int v[NMAX]; int n; int lsb(int x) { return x&(-x); } void update(int p,int val) { while(p<=n) { aib[p]+=val; p+=lsb(p); } } long long query(int p) { long long s=0; while(p>0) { s+=aib[p]; p-=lsb(p); } return s; } long long query_range(int x,int y) { return query(y)-query(x-1); } long long count_swaps(vector<int>a) { int i; long long kon=0; n=a.size(); for(i=1;i<=n;i++) v[i]=a[i-1]; for(i=1;i<=n;i++) { if(v[i]<0) left_shoe[-v[i]].push(i); else right_shoe[v[i]].push(i); } for(i=1;i<=n;i++) { if(viz[i]) continue; if(v[i]<0) { int x=left_shoe[-v[i]].front(); int y=right_shoe[-v[i]].front(); kon+=y-x-query_range(x+1,y)-1; left_shoe[-v[i]].pop(); right_shoe[-v[i]].pop(); update(x,1); update(y,1); viz[x]=true; viz[y]=true; } else { int x=right_shoe[v[i]].front(); int y=left_shoe[v[i]].front(); kon+=y-x-query_range(x+1,y); left_shoe[v[i]].pop(); right_shoe[v[i]].pop(); update(x,1); update(y,1); viz[x]=true; viz[y]=true; } } return kon; } /* int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<int>arr={2, 1, -1, -2}; //cout<<count_swaps(arr); return 0; }*/

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

shoes.cpp:3: warning: ignoring '#pragma optimize GCC' [-Wunknown-pragmas]
    3 | #pragma optimize GCC ("Ofast")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...