답안 #1034434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034434 2024-07-25T13:48:18 Z amirhoseinfar1385 Rectangles (IOI19_rect) C++17
59 / 100
977 ms 1048576 KB
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2500+10,ted=8;
long long all[maxn][maxn],vis[maxn][maxn],tp[maxn][maxn],n,m,dpp[maxn][maxn],dpd[maxn][maxn];
vector<long long>alll[maxn][maxn],alld[maxn][maxn];
vector<pair<long long,pair<long long,long long>>>allq[maxn][maxn];
vector<pair<long long,long long>>addy[maxn][maxn];
long long mainres=0;

struct fenwick{
	long long fn[maxn];
	vector<long long>allind;
	void clear(){
		for(auto x:allind){
			while(x<maxn){
				fn[x]=0;
				x+=((-x)&x);
			}
		}
		allind.clear();
	}
	void add(long long i,long long w){
		i++;
		allind.push_back(i);
		while(i<maxn){
			fn[i]+=w;
			i+=((-i)&i);
		}
	}
	long long pors(long long l,long long r){
		long long ret=0;
		r++;
		while(l>0){
			ret-=fn[l];
			l-=((-l)&l);
		}
		while(r>0){
			ret+=fn[r];
			r-=((-r)&r);
		}
		return ret;
	}
}fen;


void pre(){
	for(long long i=1;i<=n;i++){
		vector<pair<long long,long long>>allv;
		for(long long j=1;j<=m;j++){
			while((long long)allv.size()>0&&allv.back().first<all[i][j]){
				alll[i][j].push_back(allv.back().second);
				allv.pop_back();
			}
			if((long long)allv.size()>0){
				alll[i][j].push_back(allv.back().second);
			}
			if((int)allv.size()>0&&allv.back().first==all[i][j]){
				allv.pop_back();
			}
			allv.push_back(make_pair(all[i][j],j));
		}
	}
	for(long long j=1;j<=m;j++){
		vector<pair<long long,long long>>allv;
		for(long long i=n;i>=1;i--){
			while((long long)allv.size()>0&&allv.back().first<all[i][j]){
				alld[i][j].push_back(allv.back().second);
				allv.pop_back();
			}
			if((long long)allv.size()>0){
				alld[i][j].push_back(allv.back().second);
			}
			if((int)allv.size()>0&&allv.back().first==all[i][j]){
				allv.pop_back();
			}
			allv.push_back(make_pair(all[i][j],i));
		}
	}
}

void solveq(){
	for(long long i=1;i<=n;i++){
		for(long long j=1;j<=m;j++){
			sort(addy[i][j].begin(),addy[i][j].end());
			sort(allq[i][j].begin(),allq[i][j].end());
	//		cout<<i<<" "<<j<<" :"<<endl;
	//		for(auto x:addy[i][j]){
	//			cout<<x.first<<" "<<x.second<<endl;
	//		}
	//		for(auto x:allq[i][j]){
	//			cout<<x.first<<" "<<x.second.first<<" "<<x.second.second<<endl;
	//		}
			while((long long)addy[i][j].size()>0&&(long long)allq[i][j].size()>0){
				if(addy[i][j].back().first>=allq[i][j].back().first){
					fen.add(addy[i][j].back().second,1);
					addy[i][j].pop_back();
				}else{
					mainres+=fen.pors(allq[i][j].back().second.first,allq[i][j].back().second.second);
					allq[i][j].pop_back();
				}
			}
			while((long long)allq[i][j].size()>0){
				mainres+=fen.pors(allq[i][j].back().second.first,allq[i][j].back().second.second);
				allq[i][j].pop_back();
			}
			fen.clear();
		}
	}
}

void calq(){
	for(long long i=1;i<=n;i++){
		for(long long j=1;j<=m;j++){
			for(auto x:alld[i][j]){
				if(x<=i+1){
					continue;
				}
				dpp[x][j]=dpp[x][j-1]+1;
				allq[i+1][j+1].push_back(make_pair((x-i-1),make_pair(j-dpp[x][j],j-1)));
			}
		}
		for(long long j=1;j<=m;j++){
			for(auto x:alld[i][j]){
				if(x<=i+1){
					continue;
				}
				dpp[x][j]=0;
			}
		}
	}
	for(long long j=1;j<=m;j++){
		for(long long i=n;i>=1;i--){
			for(auto x:alll[i][j]){
				if(x+1>=j){
					continue;
				}
				dpp[i][x]=dpp[i+1][x]+1;
				addy[i][j].push_back(make_pair(dpp[i][x],x));
			}
		}
		for(long long i=n;i>=1;i--){
			for(auto x:alll[i][j]){
				if(x+1>=j){
					continue;
				}
				dpp[i][x]=0;
			}
		}
	}
}

void solve(){
	pre();
	calq();
	solveq();
}
long long count_rectangles(std::vector<std::vector<int> > a) {
	n=a.size();
	m=a[0].size();
	for(long long i=1;i<=n;i++){
		for(long long j=1;j<=m;j++){
			all[i][j]=a[i-1][j-1];
		}
	}
	solve();
	return mainres;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 592084 KB Output is correct
2 Correct 256 ms 592692 KB Output is correct
3 Correct 218 ms 592536 KB Output is correct
4 Correct 206 ms 592492 KB Output is correct
5 Correct 245 ms 592212 KB Output is correct
6 Correct 222 ms 592464 KB Output is correct
7 Correct 226 ms 592464 KB Output is correct
8 Correct 237 ms 592208 KB Output is correct
9 Correct 221 ms 592464 KB Output is correct
10 Correct 222 ms 592468 KB Output is correct
11 Correct 243 ms 592468 KB Output is correct
12 Correct 228 ms 592400 KB Output is correct
13 Correct 255 ms 592212 KB Output is correct
14 Correct 225 ms 592240 KB Output is correct
15 Correct 242 ms 592200 KB Output is correct
16 Correct 228 ms 592248 KB Output is correct
17 Correct 226 ms 591988 KB Output is correct
18 Correct 256 ms 592208 KB Output is correct
19 Correct 238 ms 592328 KB Output is correct
20 Correct 243 ms 592212 KB Output is correct
21 Correct 229 ms 592208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 592084 KB Output is correct
2 Correct 256 ms 592692 KB Output is correct
3 Correct 218 ms 592536 KB Output is correct
4 Correct 206 ms 592492 KB Output is correct
5 Correct 245 ms 592212 KB Output is correct
6 Correct 222 ms 592464 KB Output is correct
7 Correct 226 ms 592464 KB Output is correct
8 Correct 237 ms 592208 KB Output is correct
9 Correct 221 ms 592464 KB Output is correct
10 Correct 222 ms 592468 KB Output is correct
11 Correct 243 ms 592468 KB Output is correct
12 Correct 228 ms 592400 KB Output is correct
13 Correct 255 ms 592212 KB Output is correct
14 Correct 225 ms 592240 KB Output is correct
15 Correct 242 ms 592200 KB Output is correct
16 Correct 228 ms 592248 KB Output is correct
17 Correct 226 ms 591988 KB Output is correct
18 Correct 256 ms 592208 KB Output is correct
19 Correct 238 ms 592328 KB Output is correct
20 Correct 243 ms 592212 KB Output is correct
21 Correct 229 ms 592208 KB Output is correct
22 Correct 226 ms 593696 KB Output is correct
23 Correct 268 ms 593780 KB Output is correct
24 Correct 241 ms 593908 KB Output is correct
25 Correct 222 ms 593492 KB Output is correct
26 Correct 262 ms 593700 KB Output is correct
27 Correct 247 ms 593744 KB Output is correct
28 Correct 217 ms 593660 KB Output is correct
29 Correct 220 ms 593228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 592084 KB Output is correct
2 Correct 256 ms 592692 KB Output is correct
3 Correct 218 ms 592536 KB Output is correct
4 Correct 206 ms 592492 KB Output is correct
5 Correct 245 ms 592212 KB Output is correct
6 Correct 222 ms 592464 KB Output is correct
7 Correct 226 ms 592464 KB Output is correct
8 Correct 237 ms 592208 KB Output is correct
9 Correct 221 ms 592464 KB Output is correct
10 Correct 222 ms 592468 KB Output is correct
11 Correct 243 ms 592468 KB Output is correct
12 Correct 228 ms 592400 KB Output is correct
13 Correct 255 ms 592212 KB Output is correct
14 Correct 225 ms 592240 KB Output is correct
15 Correct 242 ms 592200 KB Output is correct
16 Correct 228 ms 592248 KB Output is correct
17 Correct 226 ms 593696 KB Output is correct
18 Correct 268 ms 593780 KB Output is correct
19 Correct 241 ms 593908 KB Output is correct
20 Correct 222 ms 593492 KB Output is correct
21 Correct 262 ms 593700 KB Output is correct
22 Correct 247 ms 593744 KB Output is correct
23 Correct 217 ms 593660 KB Output is correct
24 Correct 220 ms 593228 KB Output is correct
25 Correct 226 ms 591988 KB Output is correct
26 Correct 256 ms 592208 KB Output is correct
27 Correct 238 ms 592328 KB Output is correct
28 Correct 243 ms 592212 KB Output is correct
29 Correct 229 ms 592208 KB Output is correct
30 Correct 227 ms 599892 KB Output is correct
31 Correct 237 ms 599804 KB Output is correct
32 Correct 218 ms 599888 KB Output is correct
33 Correct 262 ms 598184 KB Output is correct
34 Correct 239 ms 599920 KB Output is correct
35 Correct 222 ms 600144 KB Output is correct
36 Correct 238 ms 599888 KB Output is correct
37 Correct 235 ms 599892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 592084 KB Output is correct
2 Correct 256 ms 592692 KB Output is correct
3 Correct 218 ms 592536 KB Output is correct
4 Correct 206 ms 592492 KB Output is correct
5 Correct 245 ms 592212 KB Output is correct
6 Correct 222 ms 592464 KB Output is correct
7 Correct 226 ms 592464 KB Output is correct
8 Correct 237 ms 592208 KB Output is correct
9 Correct 221 ms 592464 KB Output is correct
10 Correct 222 ms 592468 KB Output is correct
11 Correct 243 ms 592468 KB Output is correct
12 Correct 228 ms 592400 KB Output is correct
13 Correct 255 ms 592212 KB Output is correct
14 Correct 225 ms 592240 KB Output is correct
15 Correct 242 ms 592200 KB Output is correct
16 Correct 228 ms 592248 KB Output is correct
17 Correct 226 ms 593696 KB Output is correct
18 Correct 268 ms 593780 KB Output is correct
19 Correct 241 ms 593908 KB Output is correct
20 Correct 222 ms 593492 KB Output is correct
21 Correct 262 ms 593700 KB Output is correct
22 Correct 247 ms 593744 KB Output is correct
23 Correct 217 ms 593660 KB Output is correct
24 Correct 220 ms 593228 KB Output is correct
25 Correct 227 ms 599892 KB Output is correct
26 Correct 237 ms 599804 KB Output is correct
27 Correct 218 ms 599888 KB Output is correct
28 Correct 262 ms 598184 KB Output is correct
29 Correct 239 ms 599920 KB Output is correct
30 Correct 222 ms 600144 KB Output is correct
31 Correct 238 ms 599888 KB Output is correct
32 Correct 235 ms 599892 KB Output is correct
33 Correct 226 ms 591988 KB Output is correct
34 Correct 256 ms 592208 KB Output is correct
35 Correct 238 ms 592328 KB Output is correct
36 Correct 243 ms 592212 KB Output is correct
37 Correct 229 ms 592208 KB Output is correct
38 Correct 318 ms 656976 KB Output is correct
39 Correct 324 ms 654616 KB Output is correct
40 Correct 319 ms 661276 KB Output is correct
41 Correct 367 ms 659028 KB Output is correct
42 Correct 347 ms 674588 KB Output is correct
43 Correct 462 ms 674440 KB Output is correct
44 Correct 393 ms 674892 KB Output is correct
45 Correct 362 ms 669724 KB Output is correct
46 Correct 360 ms 648416 KB Output is correct
47 Correct 377 ms 653152 KB Output is correct
48 Correct 499 ms 675080 KB Output is correct
49 Correct 470 ms 677524 KB Output is correct
50 Correct 369 ms 637504 KB Output is correct
51 Correct 350 ms 634632 KB Output is correct
52 Correct 463 ms 673856 KB Output is correct
53 Correct 448 ms 674776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 592976 KB Output is correct
2 Correct 227 ms 592888 KB Output is correct
3 Correct 251 ms 592728 KB Output is correct
4 Correct 252 ms 592208 KB Output is correct
5 Correct 233 ms 592976 KB Output is correct
6 Correct 220 ms 593040 KB Output is correct
7 Correct 249 ms 593008 KB Output is correct
8 Correct 232 ms 592976 KB Output is correct
9 Correct 232 ms 592824 KB Output is correct
10 Correct 224 ms 592244 KB Output is correct
11 Correct 216 ms 592620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 591988 KB Output is correct
2 Correct 256 ms 592208 KB Output is correct
3 Correct 238 ms 592328 KB Output is correct
4 Correct 243 ms 592212 KB Output is correct
5 Correct 229 ms 592208 KB Output is correct
6 Correct 215 ms 592212 KB Output is correct
7 Correct 977 ms 892752 KB Output is correct
8 Runtime error 799 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 592084 KB Output is correct
2 Correct 256 ms 592692 KB Output is correct
3 Correct 218 ms 592536 KB Output is correct
4 Correct 206 ms 592492 KB Output is correct
5 Correct 245 ms 592212 KB Output is correct
6 Correct 222 ms 592464 KB Output is correct
7 Correct 226 ms 592464 KB Output is correct
8 Correct 237 ms 592208 KB Output is correct
9 Correct 221 ms 592464 KB Output is correct
10 Correct 222 ms 592468 KB Output is correct
11 Correct 243 ms 592468 KB Output is correct
12 Correct 228 ms 592400 KB Output is correct
13 Correct 255 ms 592212 KB Output is correct
14 Correct 225 ms 592240 KB Output is correct
15 Correct 242 ms 592200 KB Output is correct
16 Correct 228 ms 592248 KB Output is correct
17 Correct 226 ms 593696 KB Output is correct
18 Correct 268 ms 593780 KB Output is correct
19 Correct 241 ms 593908 KB Output is correct
20 Correct 222 ms 593492 KB Output is correct
21 Correct 262 ms 593700 KB Output is correct
22 Correct 247 ms 593744 KB Output is correct
23 Correct 217 ms 593660 KB Output is correct
24 Correct 220 ms 593228 KB Output is correct
25 Correct 227 ms 599892 KB Output is correct
26 Correct 237 ms 599804 KB Output is correct
27 Correct 218 ms 599888 KB Output is correct
28 Correct 262 ms 598184 KB Output is correct
29 Correct 239 ms 599920 KB Output is correct
30 Correct 222 ms 600144 KB Output is correct
31 Correct 238 ms 599888 KB Output is correct
32 Correct 235 ms 599892 KB Output is correct
33 Correct 318 ms 656976 KB Output is correct
34 Correct 324 ms 654616 KB Output is correct
35 Correct 319 ms 661276 KB Output is correct
36 Correct 367 ms 659028 KB Output is correct
37 Correct 347 ms 674588 KB Output is correct
38 Correct 462 ms 674440 KB Output is correct
39 Correct 393 ms 674892 KB Output is correct
40 Correct 362 ms 669724 KB Output is correct
41 Correct 360 ms 648416 KB Output is correct
42 Correct 377 ms 653152 KB Output is correct
43 Correct 499 ms 675080 KB Output is correct
44 Correct 470 ms 677524 KB Output is correct
45 Correct 369 ms 637504 KB Output is correct
46 Correct 350 ms 634632 KB Output is correct
47 Correct 463 ms 673856 KB Output is correct
48 Correct 448 ms 674776 KB Output is correct
49 Correct 240 ms 592976 KB Output is correct
50 Correct 227 ms 592888 KB Output is correct
51 Correct 251 ms 592728 KB Output is correct
52 Correct 252 ms 592208 KB Output is correct
53 Correct 233 ms 592976 KB Output is correct
54 Correct 220 ms 593040 KB Output is correct
55 Correct 249 ms 593008 KB Output is correct
56 Correct 232 ms 592976 KB Output is correct
57 Correct 232 ms 592824 KB Output is correct
58 Correct 224 ms 592244 KB Output is correct
59 Correct 216 ms 592620 KB Output is correct
60 Correct 215 ms 592212 KB Output is correct
61 Correct 977 ms 892752 KB Output is correct
62 Runtime error 799 ms 1048576 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -