#include #include #include #include #include #include #include using namespace std; #define ll long long #define vll vector #define vvll vector #define vvvll vector template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #ifdef LOCAL #include "../../cpp-dump/dump.hpp" #else #define cpp_dump #endif static uint32_t xor128(void){ static uint32_t x=123456789,y=362436069,z=521288629,w=88675123; uint32_t t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } int randrange(int a){return (uint64_t(xor128()) * a >> 32); } double randDouble(double a,double b){return a+(b-a)*xor128()/(double)ULONG_MAX;} inline double get_time() { using namespace std::chrono; return duration_cast(system_clock::now().time_since_epoch()).count(); } double start_time = get_time(); struct IO{ int n; vll a,b; IO(){} void input(){ cin >> n; a.resize(n); b.resize(n); for(int i=0;i> a[i] >> b[i]; } } }; struct State{ IO *io; int n; vector> seq; State(IO& _io) : io(&_io) ,n(_io.n) {} void add(int i, int j, int k){ if(k > seq.size()){ cerr << "error : " << i << " is out of range" << endl; return; } seq.insert(seq.begin()+k,{i,j}); } void del(int i){ if(i>=seq.size()){ cerr << "seq size is " << seq.size() << " but i is " << i << endl; return; } seq.erase(seq.begin()+i); } void update(){ int coin = randrange(10); if(seq.size()==0 || (coin < 3 && seq.size() < 50)){ int i = randrange(n); int j; do{ j = randrange(n); }while(i==j); int k = randrange(seq.size()+1); add(i,j,k); } else{ int i = randrange(seq.size()); del(i); } } double get_score(){ vll a = io->a; vll b = io->b; for(int i=0;ia; vll b = io->b; for(int i=0;i randDouble(0,1)){ swap(now_state, state); now_score = score; #ifdef LOCAL cerr << setprecision(15) << now_score << endl; #endif } } auto ans = now_state.seq; cout << ans.size() << endl; for(auto [x,y]:ans){ cout << x+1 << " " << y+1 << endl; } #ifdef LOCAL now_state.get_card(); #endif }