Submission #211112

#TimeUsernameProblemLanguageResultExecution timeMemory
211112wanling1212Arranging Shoes (IOI19_shoes)C++14
50 / 100
1090 ms146296 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; #define pb push_back #define rep(i,n) for(ll i=0;i<n;i++) #define rep1(i,n) for(ll i=1;i<=n;i++) #define mp make_pair #define F first #define S second #define pf pop_front #define IOS ios_base::sync_with_stdio(0); cin.tie(0) typedef long long ll; const ll mod=1e9+7; const ll maxn=200005; const ll inf=1e9+7; unordered_map<ll,queue<ll>> m; ll bit[maxn]; ll lsb(int x) { return x&(-x); } void add(int x,int v) { while(x<maxn) { bit[x]+=v; x+=lsb(x); } } ll query(ll x) { ll res=0; while(x) { res+=bit[x]; x-=lsb(x); } return res; } ll count_swaps(std::vector<int> s) { rep(i,s.size()) { m[s[i]].push(i); add(i+1,1); } ll sum=0; rep(i,s.size()) { queue<ll> q=m[-s[i]]; if(q.empty()) continue; if(m[s[i]].front()!=i) continue; ll p=q.front(); m[-s[i]].pop(); m[s[i]].pop(); sum+=query(p)-query(i+1); if(s[i]>0) sum++; //cout<<i<<" "<<sum<<"\n"; add(p+1,-1); add(i+1,-1); } return sum; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:5:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(ll i=0;i<n;i++)
shoes.cpp:42:9:
     rep(i,s.size())
         ~~~~~~~~~~            
shoes.cpp:42:5: note: in expansion of macro 'rep'
     rep(i,s.size())
     ^~~
shoes.cpp:5:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(ll i=0;i<n;i++)
shoes.cpp:48:9:
     rep(i,s.size())
         ~~~~~~~~~~            
shoes.cpp:48:5: note: in expansion of macro 'rep'
     rep(i,s.size())
     ^~~
#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...