Submission #232388

# Submission time Handle Problem Language Result Execution time Memory
232388 2020-05-16T22:15:41 Z crossing0ver Quality Of Living (IOI10_quality) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
//#include "quality.h"
using namespace std;
const int N = 1E5 + 5;
int median;

int t[4*N];
int pos,numb,L,R,ans;
int Q[3001][3001];
void upd (int v = 1,int tl = 0,int tr = numb) {
	if (tl == tr) {
		if (t[v]) t[v] = 0;
		else t[v] = 1;
		return;
	}
	int tm = (tl +tr)/2;
	if (pos <= tm)
		upd (v*2,tl,tm);
	else upd (v*2|1,tm+1,tr);
	t[v] = t[v*2] + t[v*2 + 1];
}
int get (int v = 1, int tl = 0, int tr = numb,int F = median) {
	if (tl == tr) return tl;
	int tm = (tl + tr)/2;
	if (F <= t[v*2]) return get(v*2,tl,tm,F);
	F -= t[v*2];
	return get(v*2|1,tm+1,tr,F);
}
int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
	numb = H*W;
	median = (numb + 1)/2;
	for (int i = 0; i < R; i++)
	for (int j = 0; j < H; j++) {
		pos = Q[i][j];
		upd();
	}
	
	int r = W - 1, l = 0, h = 0, d = H - 1;
	int dir = 0; // 0 - r  1 - d   2 - l
	while (true) {
		ans = max(ans,get());
		if (dir == 0) {
			if (r != C - 1) {
				for (int i = h; i <= d; i++) {
					pos = Q[i][l];
					upd();
					pos = Q[i][r + 1];
					upd();
				}
				r++;
				l++;																		
			}
			else if (d != R - 1){
				dir = 1;
				for (int i = l; i <=r ; i++) {
					pos = Q[h][i];
					upd();
					pos = Q[d + 1][i];
					upd();
				}
				h++;
				d++;
			}
			else break;
		}
		else {
			if (dir == 1) {
				if (l != 0) {
					for (int i = h; i <= d; i++) {
					pos = Q[i][r];
					upd();
					pos = Q[i][l-1];
					upd();
				}
				r--;
				l--;
				dir = 2;
			}
			else if (r != C - 1) {
				for (int i = h; i <= d; i++) {
					pos = Q[i][l];
					upd();
					pos = Q[i][r + 1];
					upd();
				}
				r++;
				l++;
				dir = 0;																		
			}
			else if (d != R - 1) {
				dir = 1;
				for (int i = l; i <=r ; i++) {
					pos = Q[h][i];
					upd();
					pos = Q[d + 1][i];
					upd();
				}
				h++;
				d++;
			}
			else break;
			}
			else {
				if (l != 0) {
					for (int i = h; i <= d; i++) {
					pos = Q[i][r];
					upd();
					pos = Q[i][l-1];
					upd();
				}
				r--;
				l--;
				dir = 0;
			}
			else if (d != R - 1) {
				dir = 1;
				for (int i = l; i <=r ; i++) {
					pos = Q[h][i];
					upd();
					pos = Q[d + 1][i];
					upd();
				}
				h++;
				d++;
			}
			else break;
			}
		}
	}
	return ans;
	
	//return R*C/2;
}

main () {
	int R,C,H,W;
//	int Q[3001][3001] = {};
	scanf("%d%d%d%d",&R,&C,&H,&W);
   for (int i=0;i<R;i++) for (int j=0;j<C;j++) scanf("%d",&Q[i][j]);
   int ans = rectangle(R,C,H,W,Q);
   printf("%d\n",ans);
   return 0;
}

Compilation message

quality.cpp:135:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
quality.cpp: In function 'int main()':
quality.cpp:138:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&R,&C,&H,&W);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
quality.cpp:139:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    for (int i=0;i<R;i++) for (int j=0;j<C;j++) scanf("%d",&Q[i][j]);
                                                ~~~~~^~~~~~~~~~~~~~~
/tmp/ccyoAznh.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccUiGxhE.o:quality.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status