Submission #163345

# Submission time Handle Problem Language Result Execution time Memory
163345 2019-11-12T18:02:41 Z MvC Swap (BOI16_swap) C++11
100 / 100
197 ms 16248 KB
#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

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 time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 22 ms 2140 KB Output is correct
17 Correct 21 ms 2040 KB Output is correct
18 Correct 22 ms 2040 KB Output is correct
19 Correct 43 ms 4324 KB Output is correct
20 Correct 43 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 22 ms 2140 KB Output is correct
17 Correct 21 ms 2040 KB Output is correct
18 Correct 22 ms 2040 KB Output is correct
19 Correct 43 ms 4324 KB Output is correct
20 Correct 43 ms 4344 KB Output is correct
21 Correct 88 ms 7536 KB Output is correct
22 Correct 84 ms 7516 KB Output is correct
23 Correct 84 ms 7516 KB Output is correct
24 Correct 197 ms 16248 KB Output is correct
25 Correct 194 ms 16120 KB Output is correct