Submission #200669

#TimeUsernameProblemLanguageResultExecution timeMemory
200669FerThugGato12500Arranging Shoes (IOI19_shoes)C++14
100 / 100
362 ms277508 KiB
#include "shoes.h" #include<iostream> #include<queue> using namespace std; queue<int> closer[2][200001]; int comp[200001]; bool vis[200001]; typedef struct { int st[800001]; int N, x, y; void build() { for(int i = 0; i < N*4; i++) st[i]=0; return; } int query(int stf, int stf2) { x=stf; y=stf2; return query(0, N-1, 0); } int query(int ini, int fin, int ind) { if(ini>y || x>fin) return 0; if(ini>=x && y>=fin) return st[ind]; int mit = (ini+fin)/2, ls=(ind*2)+1, rs=(ind*2)+2; return query(ini, mit, ls)+query(mit+1, fin, rs); } void insert(int stf) { x=stf; insert(0, N-1, 0); return; } void insert(int ini, int fin, int ind) { if(ini==fin) { st[ind]++; return; } int mit = (ini+fin)/2, ls=(2*ind)+1, rs=(2*ind)+2; if(x<=mit) insert(ini, mit, ls); else insert(mit+1, fin, rs); st[ind] = st[ls]+st[rs]; return; } }Wasd; Wasd mqun; long long d=0; long long count_swaps(vector<int> s) { int n = s.size(); for(int i = 0; i < n; i++) comp[i]=s[i]; for(int i = 0; i < n; i++) if(comp[i]<0) closer[1][comp[i]*-1].push(i); else closer[0][comp[i]].push(i); mqun.N=n; mqun.build(); for(int i = 0; i < n; i++) if(!vis[i]) { bool z = false; if(comp[i]>0) z=true; else comp[i]*=-1; int j = closer[z][comp[i]].front(); closer[z][comp[i]].pop(); closer[!z][comp[i]].pop(); d+=((j-i+z)-1)-mqun.query(i, j); vis[i]=true; vis[j]=true; mqun.insert(j); } return d; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:67:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i = 0; i < n; i++)
     ^~~
shoes.cpp:82:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return d;
  ^~~~~~
#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...