Submission #469326

#TimeUsernameProblemLanguageResultExecution timeMemory
469326AdamGSArranging Shoes (IOI19_shoes)C++14
100 / 100
101 ms18060 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e5+7; vector<int>V[2*LIM]; ll li[2*LIM], tr[8*LIM], N=1; void upd(int v) { v+=N; while(v) { --tr[v]; v/=2; } } ll cnt(int l, int r) { if(l>r) return 0; l+=N; r+=N; ll ans=tr[l]; if(l!=r) ans+=tr[r]; while(l/2!=r/2) { if(l%2==0) ans+=tr[l+1]; if(r%2==1) ans+=tr[r-1]; l/=2; r/=2; } return ans; } ll count_swaps(vector<int>S) { while(N<S.size()) N*=2; rep(i, S.size()) { tr[N+i]=1; if(S[i]<0) V[-S[i]+LIM].pb(i); else V[S[i]].pb(i); } for(int i=N-1; i>=0; --i) tr[i]=tr[2*i]+tr[2*i+1]; ll ans=0; rep(i, S.size()) if(tr[N+i]) { if(S[i]<0) { ans+=cnt(i+1, V[-S[i]][li[-S[i]]]-1); upd(V[-S[i]][li[-S[i]]]); ++li[-S[i]]; ++li[-S[i]+LIM]; } else { ans+=cnt(i+1, V[S[i]+LIM][li[S[i]+LIM]]-1)+1; upd(V[S[i]+LIM][li[S[i]+LIM]]); ++li[S[i]+LIM]; ++li[S[i]]; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:34:9: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  while(N<S.size()) N*=2;
      |        ~^~~~~~~~~
shoes.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
shoes.cpp:35:2: note: in expansion of macro 'rep'
   35 |  rep(i, S.size()) {
      |  ^~~
shoes.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
shoes.cpp:42:2: note: in expansion of macro 'rep'
   42 |  rep(i, S.size()) if(tr[N+i]) {
      |  ^~~
#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...