Submission #163345

#TimeUsernameProblemLanguageResultExecution timeMemory
163345MvCSwap (BOI16_swap)C++11
100 / 100
197 ms16248 KiB
#include<cstdio> #include<iostream> #include<cstdlib> #include<cmath> #include<vector> #include<algorithm> #include<set> #include<map> #include<queue> #include<cstring> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define VI vector<int> #define PII pair<int,int> #define st first #define nd second #define mp make_pair #define pb push_back #define lint long long int #define debug(x) {cerr <<#x <<" = " <<x <<endl; } #define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } #define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }} #define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }} #define make( x) int (x); scanf("%d",&(x)); #define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y)); #define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z)); #define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t)); #define IOS ios_base::sync_with_stdio(0) #define HEAP priority_queue #define read( x) scanf("%d",&(x)); #define read2( x, y) scanf("%d%d",&(x),&(y)); #define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z)); #define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t)); using namespace std; const int max_n = 2e5+5; int t[max_n]; int n; map<PII, PII> mem; PII pos(int v, int num) { if (2*v > n) return mp(v,0); int a = t[2*v]; int b = t[2*v+1]; if (num < a && num < b) return mp(v,0); if (b > a && num > a) return mp(pos(2*v,num).st,-1); if (mem.find(mp(v, num))!=mem.end()) return mem[mp(v,num)]; if (num < a) { int p1 = pos(2*v, num).st; int p2 = pos(2*v+1, num).st; if (p1 < p2) { mem[mp(v, num)] = mp(p1,-2); return mp(p1,-2); } else { mem[mp(v, num)] = mp(p2,1); return mp(p2,1); } } else { int q1 = pos(2*v, a).st; int q2 = pos(2*v+1, a).st; if (q1 < q2) { int p2 = pos(2*v+1, num).st; mem[mp(v, num)] = mp(p2,1); return mp(p2, 1); } else { int p1 = pos(2*v, num).st; mem[mp(v, num)] = mp(p1,-2); return mp(p1,-2); } } } int main() { read(n); FOR(i,0,n) { make(a); t[i+1] = a; } t[n+1] = 1e9; FOR(v,1,n/2 + 1) { PII xxx = pos(v, t[v]); if (xxx.nd == 1) swap(t[v], t[2*v+1]); if (xxx.nd == -1) swap(t[v], t[2*v]); if (xxx.nd == -2) { swap(t[v], t[2*v]); swap(t[v], t[2*v+1]); } } FOR(i,1,n+1) { printf("%d ", t[i]); } printf("\n"); }

Compilation message (stderr)

swap.cpp: In function 'int main()':
swap.cpp:38:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define read( x) scanf("%d",&(x));
                  ~~~~~^~~~~~~~~~~
swap.cpp:85:2: note: in expansion of macro 'read'
  read(n);
  ^~~~
swap.cpp:31:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define make( x) int (x); scanf("%d",&(x));
                           ~~~~~^~~~~~~~~~~
swap.cpp:87:3: note: in expansion of macro 'make'
   make(a);
   ^~~~
#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...