제출 #849891

#제출 시각아이디문제언어결과실행 시간메모리
849891tosivanmakArranging Shoes (IOI19_shoes)C++17
10 / 100
15 ms19172 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long struct pairs{ ll l,r; bool operator<(const pairs& p)const{ // l,r,p.l,p.r ll cnt=0; if(r<l){ cnt++; } if(p.l<l){ cnt++; } if(p.l<r){ cnt++; } if(p.r<l){ cnt++; } if(p.r<r){ cnt++; } if(p.r<p.l){ cnt++; } ll cnt2=0; if(p.r<p.l){ cnt2++; } if(l<p.l){ cnt2++; } if(l<p.r){ cnt2++; } if(r<p.l){ cnt2++; } if(r<p.r){ cnt2++; } if(r<l){ cnt2++; } // cout<<1; return cnt>=cnt2; } }; struct FEN{ vector<ll>fen; void init(ll n){ fen.resize(n+5); for(int i=0;i<=n+4;i++){ fen[i]=0; } } void upd(ll n, ll m, ll val){ for(int i=n;i<=m;i+=i&(-i)){ fen[i]+=val; // cout<<i; } } ll sum(ll e){ ll su=0; while(e>=1){ su+=fen[e]; e-=e&(-e); } // cout<<1; return su; } }; long long count_swaps(std::vector<int> s) { vector<ll>make; vector<ll>adj[300005],adj2[300005]; for(int i=0;i<s.size();i++){ if(s[i]<0){ make.push_back(abs(s[i])); adj[abs(s[i])].push_back(i+1); } else{ adj2[s[i]].push_back(i+1); } } ll ptr[300005]; for(int i=0;i<=s.size()+4;i++){ ptr[i]=0; } vector<pairs>bruh; // for(auto u: adj[2]){ // cout<<u<<" "; // } for(int i=0;i<make.size();i++){ bruh.push_back({adj[make[i]][ptr[make[i]]],adj2[make[i]][ptr[make[i]]]}); ptr[make[i]]++; } sort(bruh.begin(),bruh.end()); vector<ll>real; for(int i=0;i<bruh.size();i++){ real.push_back(bruh[i].l); real.push_back(bruh[i].r); } // for(auto u: real){ // cout<<u<<" "; // } FEN f; f.init(300000); ll ans=0; for(int i=0;i<real.size();i++){ ans+=f.sum(300000)-f.sum(real[i]); f.upd(real[i],300000,1); } return ans; // return 0; } // #ifndef ONLINE_JUDGE // int main() { // int n; // cin>>n; // vector<int> S(2 * n); // for (int i = 0; i < 2 * n; i++){ // cin>>S[i]; // } // long long result = count_swaps(S); // cout<<result<<"\n"; // return 0; // } // #endif

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |      for(int i=0;i<s.size();i++){
      |                  ~^~~~~~~~~
shoes.cpp:89:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |      for(int i=0;i<=s.size()+4;i++){
      |                  ~^~~~~~~~~~~~
shoes.cpp:96:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |      for(int i=0;i<make.size();i++){
      |                  ~^~~~~~~~~~~~
shoes.cpp:102:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pairs>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |      for(int i=0;i<bruh.size();i++){
      |                  ~^~~~~~~~~~~~
shoes.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |      for(int i=0;i<real.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...