제출 #318043

#제출 시각아이디문제언어결과실행 시간메모리
318043lukameladze정렬하기 (IOI15_sorting)C++14
100 / 100
446 ms45756 KiB
# include <bits/stdc++.h> using namespace std; long long xx,idx[600005],a1[600005],a[600005],n,m,X[600005],Y[600005],a3[600005],ww,le,ri,mid,a2[600005],anss; vector < pair < long long, long long > > v,ans,ans1; void swapp(int idx1, int idx2) { idx[a1[idx1]]=idx2; idx[a1[idx2]]=idx1; swap(a1[idx1],a1[idx2]); } void swapp1(int idx1, int idx2) { idx[a[idx1]]=idx2; idx[a[idx2]]=idx1; swap(a[idx1],a[idx2]); } int findSwapPairs(int N, int A[], int M, int x[], int y[], int P[], int Q[]) { n=N; m=M; for (int i=1; i<=n; i++) { a2[i]=A[i-1]+1; } for (int i=1; i<=m; i++) { X[i]=x[i-1]+1; Y[i]=y[i-1]+1; } for (int i=1; i<=n; i++) { a1[i]=a2[i]; a3[i]=a2[i]; } sort(a3+1, a3+n+1); for (int i=1; i<=n; i++) { if(a3[i]!=a2[i]) ww=1; } if (!ww) { return 0; } le=1; ri=m; while(le<=ri) { ans.clear(); v.clear(); mid=(le+ri)/2; for (int i=1; i<=n; i++) { a1[i]=a2[i]; a[i]=a2[i]; } for (int i=1; i<=mid; i++) { swap(a1[X[i]], a1[Y[i]]); } for (int i=1; i<=n; i++) { idx[a1[i]]=i; } for (int i=1; i<=n; i++) { if (idx[i]!=i) { v.push_back({i, a1[i]}); } swapp(idx[a1[i]], idx[i]); } if (v.size()>mid) { le=mid+1; continue; } for (int i=1; i<=n; i++) { idx[a[i]]=i; } for (int i=1; i<=mid; i++) { swapp1(X[i],Y[i]); xx=v.size(); if (i<=xx) { ans.push_back({idx[v[i-1].first], idx[v[i-1].second]}), swapp1(idx[v[i-1].first],idx[v[i-1].second]); } } if (v.size()<=mid) { anss=mid; ri=mid-1; ans1.clear(); for (int j=0; j<ans.size(); j++) { ans1.push_back({ans[j].first, ans[j].second}); } } } //cout<<anss<<endl; while (ans1.size()<anss) ans1.push_back({1,1}); for (int i=0; i<ans1.size(); i++) { P[i]=ans1[i].first-1; Q[i]=ans1[i].second-1; //cout<<ans1[i].first<<" "<<ans1[i].second<<endl; } return anss; }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:70:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   70 |               swapp(idx[a1[i]], idx[i]);
      |                     ~~~~~~~~~^
sorting.cpp:70:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   70 |               swapp(idx[a1[i]], idx[i]);
      |                                 ~~~~~^
sorting.cpp:72:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   72 |          if (v.size()>mid)
      |              ~~~~~~~~^~~~
sorting.cpp:83:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   83 |               swapp1(X[i],Y[i]);
      |                      ~~~^
sorting.cpp:83:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   83 |               swapp1(X[i],Y[i]);
      |                           ~~~^
sorting.cpp:88:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   88 |                swapp1(idx[v[i-1].first],idx[v[i-1].second]);
      |                       ~~~~~~~~~~~~~~~~^
sorting.cpp:88:58: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   88 |                swapp1(idx[v[i-1].first],idx[v[i-1].second]);
      |                                         ~~~~~~~~~~~~~~~~~^
sorting.cpp:91:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   91 |         if (v.size()<=mid)
      |             ~~~~~~~~^~~~~
sorting.cpp:96:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |              for (int j=0; j<ans.size(); j++)
      |                            ~^~~~~~~~~~~
sorting.cpp:103:24: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  103 |      while (ans1.size()<anss)
      |             ~~~~~~~~~~~^~~~~
sorting.cpp:106:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int i=0; i<ans1.size(); i++)
      |                   ~^~~~~~~~~~~~
sorting.cpp:108:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  108 |       P[i]=ans1[i].first-1;
sorting.cpp:109:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  109 |       Q[i]=ans1[i].second-1;
sorting.cpp:112:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  112 |     return anss;
      |            ^~~~
#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...