제출 #1035364

#제출 시각아이디문제언어결과실행 시간메모리
1035364edogawa_somethingArranging Shoes (IOI19_shoes)C++17
100 / 100
205 ms33676 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vii; typedef pair<int,int> pii; #define pb push_back #define F first #define S second map<int,set<int>>s; ll sz=1; struct segtree{ vii node; void init(ll x){ sz=1; while(sz<x) sz*=2; node.clear(); node.resize(2*sz); } void update(ll i,ll x=0,ll lx=0,ll rx=sz){ if(rx-lx==1){ node[x]=1; return; } int mid=((lx+rx)>>1); if(i<mid) update(i,x*2+1,lx,mid); else update(i,x*2+2,mid,rx); node[x]=node[x*2+1]+node[x*2+2]; } int query(ll l,ll x=0,ll lx=0,ll rx=sz){ if(lx>=l) return node[x]; if(rx<=l) return 0; int mid=((lx+rx)>>1); return query(l,x*2+1,lx,mid)+query(l,x*2+2,mid,rx); } }seg; bool vis[300010]; ll count_swaps(vector<int>a) { s.clear(); seg.init(a.size()); for(int i=0;i<a.size();i++) s[a[i]].insert(i),vis[i]=0; ll ans=0; for(int i=0;i<a.size();i++){ if(vis[i]) continue; auto it=s[-a[i]].upper_bound(i); ll ind=*it+seg.query(*it); ll ii=i+seg.query(i); vis[*it]=vis[i]=1; seg.update(*it); s[-a[i]].erase(it); ans+=ind-ii-1; if(a[i]>0) ans++; } return ans; }

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

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int i=0;i<a.size();i++)
      |               ~^~~~~~~~~
shoes.cpp:49:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i=0;i<a.size();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...