답안 #1034905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034905 2024-07-25T20:56:45 Z amirhoseinfar1385 Rectangles (IOI19_rect) C++17
72 / 100
2116 ms 1048580 KB
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=2500+10;
int all[maxn][maxn],n,m,dpp[maxn][maxn];
vector<int>alll[maxn][maxn],alld[maxn][maxn];
vector<pair<int,int>>allq[maxn][maxn];
vector<pair<int,int>>addy[maxn];
long long mainres=0;

struct fenwick{
	int fn[maxn];
	vector<int>allind;
	void clear(){
		for(auto x:allind){
			while(x<maxn){
				fn[x]=0;
				x+=((-x)&x);
			}
		}
		allind.shrink_to_fit();
		allind.clear();
	}
	void add(int i,int w){
		i++;
		allind.push_back(i);
		while(i<maxn){
			fn[i]+=w;
			i+=((-i)&i);
		}
	}
	int pors(int l,int r){
		int 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 solveq(int i,int j){
	sort(addy[i].begin(),addy[i].end());
	sort(allq[i][j].begin(),allq[i][j].end());
	while((int)addy[i].size()>0&&(int)allq[i][j].size()>0){
		if(addy[i].back().first>=allq[i][j].back().first){
			fen.add(addy[i].back().second,1);
			addy[i].pop_back();
		}else{
			mainres+=fen.pors(allq[i][j].back().second,j-2);
			allq[i][j].pop_back();
		}
	}
	while((int)allq[i][j].size()>0){
		mainres+=fen.pors(allq[i][j].back().second,j-2);
		allq[i][j].pop_back();
	}
	fen.clear();
}


void calq(){
	for(int j=1;j<=m;j++){
		vector<pair<int,int>>allv;
		for(int i=n;i>=1;i--){
			while((int)allv.size()>0&&allv.back().first<all[i][j]){
				alld[i][j].push_back(allv.back().second);
				allv.pop_back();
			}
			if((int)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));
		}
	}
	for(int i=1;i<=n;i++){
		for(int 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),j-dpp[x][j]));
			}
		}
		for(int j=1;j<=m;j++){
			for(auto x:alld[i][j]){
				if(x<=i+1){
					continue;
				}
				dpp[x][j]=0;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			alld[i][j].clear();
		}
	}



	for(int i=1;i<=n;i++){
		vector<pair<int,int>>allv;
		for(int j=1;j<=m;j++){
			while((int)allv.size()>0&&allv.back().first<all[i][j]){
				alll[i][j].push_back(allv.back().second);
				allv.pop_back();
			}
			if((int)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(int j=1;j<=m;j++){
		for(int 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].push_back(make_pair(dpp[i][x],x));
			}
			solveq(i,j);
		}
		for(int i=n;i>=1;i--){
			for(auto x:alll[i][j]){
				if(x+1>=j){
					continue;
				}
				dpp[i][x]=0;
			}
			addy[i].clear();
			allq[i][j].clear();
			addy[i].shrink_to_fit();
			allq[i][j].shrink_to_fit();
		}
	}
}

void solve(){
	calq();
}
long long count_rectangles(std::vector<std::vector<int> > a) {
	n=a.size();
	m=a[0].size();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			all[i][j]=a[i-1][j-1];
		}
	}
	solve();
	return mainres;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 444240 KB Output is correct
2 Correct 161 ms 444500 KB Output is correct
3 Correct 157 ms 444596 KB Output is correct
4 Correct 160 ms 444624 KB Output is correct
5 Correct 165 ms 444288 KB Output is correct
6 Correct 162 ms 444668 KB Output is correct
7 Correct 156 ms 444536 KB Output is correct
8 Correct 157 ms 444420 KB Output is correct
9 Correct 154 ms 444496 KB Output is correct
10 Correct 160 ms 444596 KB Output is correct
11 Correct 151 ms 444500 KB Output is correct
12 Correct 157 ms 444496 KB Output is correct
13 Correct 157 ms 444244 KB Output is correct
14 Correct 147 ms 444172 KB Output is correct
15 Correct 162 ms 444240 KB Output is correct
16 Correct 153 ms 444368 KB Output is correct
17 Correct 153 ms 444244 KB Output is correct
18 Correct 159 ms 444244 KB Output is correct
19 Correct 155 ms 444496 KB Output is correct
20 Correct 150 ms 444244 KB Output is correct
21 Correct 160 ms 444224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 444240 KB Output is correct
2 Correct 161 ms 444500 KB Output is correct
3 Correct 157 ms 444596 KB Output is correct
4 Correct 160 ms 444624 KB Output is correct
5 Correct 165 ms 444288 KB Output is correct
6 Correct 162 ms 444668 KB Output is correct
7 Correct 156 ms 444536 KB Output is correct
8 Correct 157 ms 444420 KB Output is correct
9 Correct 154 ms 444496 KB Output is correct
10 Correct 160 ms 444596 KB Output is correct
11 Correct 151 ms 444500 KB Output is correct
12 Correct 157 ms 444496 KB Output is correct
13 Correct 157 ms 444244 KB Output is correct
14 Correct 147 ms 444172 KB Output is correct
15 Correct 162 ms 444240 KB Output is correct
16 Correct 153 ms 444368 KB Output is correct
17 Correct 153 ms 444244 KB Output is correct
18 Correct 159 ms 444244 KB Output is correct
19 Correct 155 ms 444496 KB Output is correct
20 Correct 150 ms 444244 KB Output is correct
21 Correct 160 ms 444224 KB Output is correct
22 Correct 171 ms 445524 KB Output is correct
23 Correct 152 ms 445520 KB Output is correct
24 Correct 157 ms 445524 KB Output is correct
25 Correct 151 ms 445400 KB Output is correct
26 Correct 157 ms 445520 KB Output is correct
27 Correct 154 ms 445524 KB Output is correct
28 Correct 153 ms 445424 KB Output is correct
29 Correct 160 ms 445268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 444240 KB Output is correct
2 Correct 161 ms 444500 KB Output is correct
3 Correct 157 ms 444596 KB Output is correct
4 Correct 160 ms 444624 KB Output is correct
5 Correct 165 ms 444288 KB Output is correct
6 Correct 162 ms 444668 KB Output is correct
7 Correct 156 ms 444536 KB Output is correct
8 Correct 157 ms 444420 KB Output is correct
9 Correct 154 ms 444496 KB Output is correct
10 Correct 160 ms 444596 KB Output is correct
11 Correct 151 ms 444500 KB Output is correct
12 Correct 157 ms 444496 KB Output is correct
13 Correct 157 ms 444244 KB Output is correct
14 Correct 147 ms 444172 KB Output is correct
15 Correct 162 ms 444240 KB Output is correct
16 Correct 153 ms 444368 KB Output is correct
17 Correct 171 ms 445524 KB Output is correct
18 Correct 152 ms 445520 KB Output is correct
19 Correct 157 ms 445524 KB Output is correct
20 Correct 151 ms 445400 KB Output is correct
21 Correct 157 ms 445520 KB Output is correct
22 Correct 154 ms 445524 KB Output is correct
23 Correct 153 ms 445424 KB Output is correct
24 Correct 160 ms 445268 KB Output is correct
25 Correct 153 ms 444244 KB Output is correct
26 Correct 159 ms 444244 KB Output is correct
27 Correct 155 ms 444496 KB Output is correct
28 Correct 150 ms 444244 KB Output is correct
29 Correct 160 ms 444224 KB Output is correct
30 Correct 158 ms 450384 KB Output is correct
31 Correct 159 ms 450384 KB Output is correct
32 Correct 168 ms 450388 KB Output is correct
33 Correct 164 ms 449320 KB Output is correct
34 Correct 162 ms 449784 KB Output is correct
35 Correct 165 ms 449640 KB Output is correct
36 Correct 166 ms 449620 KB Output is correct
37 Correct 160 ms 449616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 444240 KB Output is correct
2 Correct 161 ms 444500 KB Output is correct
3 Correct 157 ms 444596 KB Output is correct
4 Correct 160 ms 444624 KB Output is correct
5 Correct 165 ms 444288 KB Output is correct
6 Correct 162 ms 444668 KB Output is correct
7 Correct 156 ms 444536 KB Output is correct
8 Correct 157 ms 444420 KB Output is correct
9 Correct 154 ms 444496 KB Output is correct
10 Correct 160 ms 444596 KB Output is correct
11 Correct 151 ms 444500 KB Output is correct
12 Correct 157 ms 444496 KB Output is correct
13 Correct 157 ms 444244 KB Output is correct
14 Correct 147 ms 444172 KB Output is correct
15 Correct 162 ms 444240 KB Output is correct
16 Correct 153 ms 444368 KB Output is correct
17 Correct 171 ms 445524 KB Output is correct
18 Correct 152 ms 445520 KB Output is correct
19 Correct 157 ms 445524 KB Output is correct
20 Correct 151 ms 445400 KB Output is correct
21 Correct 157 ms 445520 KB Output is correct
22 Correct 154 ms 445524 KB Output is correct
23 Correct 153 ms 445424 KB Output is correct
24 Correct 160 ms 445268 KB Output is correct
25 Correct 158 ms 450384 KB Output is correct
26 Correct 159 ms 450384 KB Output is correct
27 Correct 168 ms 450388 KB Output is correct
28 Correct 164 ms 449320 KB Output is correct
29 Correct 162 ms 449784 KB Output is correct
30 Correct 165 ms 449640 KB Output is correct
31 Correct 166 ms 449620 KB Output is correct
32 Correct 160 ms 449616 KB Output is correct
33 Correct 153 ms 444244 KB Output is correct
34 Correct 159 ms 444244 KB Output is correct
35 Correct 155 ms 444496 KB Output is correct
36 Correct 150 ms 444244 KB Output is correct
37 Correct 160 ms 444224 KB Output is correct
38 Correct 256 ms 496212 KB Output is correct
39 Correct 263 ms 493904 KB Output is correct
40 Correct 242 ms 493908 KB Output is correct
41 Correct 246 ms 491600 KB Output is correct
42 Correct 275 ms 506192 KB Output is correct
43 Correct 272 ms 506192 KB Output is correct
44 Correct 271 ms 506192 KB Output is correct
45 Correct 263 ms 502200 KB Output is correct
46 Correct 268 ms 491912 KB Output is correct
47 Correct 264 ms 493272 KB Output is correct
48 Correct 330 ms 498200 KB Output is correct
49 Correct 369 ms 498168 KB Output is correct
50 Correct 256 ms 473936 KB Output is correct
51 Correct 259 ms 471076 KB Output is correct
52 Correct 331 ms 497740 KB Output is correct
53 Correct 339 ms 497584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 445012 KB Output is correct
2 Correct 166 ms 444752 KB Output is correct
3 Correct 159 ms 444784 KB Output is correct
4 Correct 152 ms 444240 KB Output is correct
5 Correct 152 ms 444756 KB Output is correct
6 Correct 150 ms 444664 KB Output is correct
7 Correct 166 ms 444756 KB Output is correct
8 Correct 163 ms 444776 KB Output is correct
9 Correct 181 ms 444760 KB Output is correct
10 Correct 164 ms 444428 KB Output is correct
11 Correct 177 ms 444496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 444244 KB Output is correct
2 Correct 159 ms 444244 KB Output is correct
3 Correct 155 ms 444496 KB Output is correct
4 Correct 150 ms 444244 KB Output is correct
5 Correct 160 ms 444224 KB Output is correct
6 Correct 153 ms 444232 KB Output is correct
7 Correct 925 ms 692836 KB Output is correct
8 Correct 1820 ms 979792 KB Output is correct
9 Correct 1793 ms 982296 KB Output is correct
10 Correct 1969 ms 982612 KB Output is correct
11 Correct 633 ms 673540 KB Output is correct
12 Correct 1095 ms 881748 KB Output is correct
13 Correct 1185 ms 909144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 444240 KB Output is correct
2 Correct 161 ms 444500 KB Output is correct
3 Correct 157 ms 444596 KB Output is correct
4 Correct 160 ms 444624 KB Output is correct
5 Correct 165 ms 444288 KB Output is correct
6 Correct 162 ms 444668 KB Output is correct
7 Correct 156 ms 444536 KB Output is correct
8 Correct 157 ms 444420 KB Output is correct
9 Correct 154 ms 444496 KB Output is correct
10 Correct 160 ms 444596 KB Output is correct
11 Correct 151 ms 444500 KB Output is correct
12 Correct 157 ms 444496 KB Output is correct
13 Correct 157 ms 444244 KB Output is correct
14 Correct 147 ms 444172 KB Output is correct
15 Correct 162 ms 444240 KB Output is correct
16 Correct 153 ms 444368 KB Output is correct
17 Correct 171 ms 445524 KB Output is correct
18 Correct 152 ms 445520 KB Output is correct
19 Correct 157 ms 445524 KB Output is correct
20 Correct 151 ms 445400 KB Output is correct
21 Correct 157 ms 445520 KB Output is correct
22 Correct 154 ms 445524 KB Output is correct
23 Correct 153 ms 445424 KB Output is correct
24 Correct 160 ms 445268 KB Output is correct
25 Correct 158 ms 450384 KB Output is correct
26 Correct 159 ms 450384 KB Output is correct
27 Correct 168 ms 450388 KB Output is correct
28 Correct 164 ms 449320 KB Output is correct
29 Correct 162 ms 449784 KB Output is correct
30 Correct 165 ms 449640 KB Output is correct
31 Correct 166 ms 449620 KB Output is correct
32 Correct 160 ms 449616 KB Output is correct
33 Correct 256 ms 496212 KB Output is correct
34 Correct 263 ms 493904 KB Output is correct
35 Correct 242 ms 493908 KB Output is correct
36 Correct 246 ms 491600 KB Output is correct
37 Correct 275 ms 506192 KB Output is correct
38 Correct 272 ms 506192 KB Output is correct
39 Correct 271 ms 506192 KB Output is correct
40 Correct 263 ms 502200 KB Output is correct
41 Correct 268 ms 491912 KB Output is correct
42 Correct 264 ms 493272 KB Output is correct
43 Correct 330 ms 498200 KB Output is correct
44 Correct 369 ms 498168 KB Output is correct
45 Correct 256 ms 473936 KB Output is correct
46 Correct 259 ms 471076 KB Output is correct
47 Correct 331 ms 497740 KB Output is correct
48 Correct 339 ms 497584 KB Output is correct
49 Correct 155 ms 445012 KB Output is correct
50 Correct 166 ms 444752 KB Output is correct
51 Correct 159 ms 444784 KB Output is correct
52 Correct 152 ms 444240 KB Output is correct
53 Correct 152 ms 444756 KB Output is correct
54 Correct 150 ms 444664 KB Output is correct
55 Correct 166 ms 444756 KB Output is correct
56 Correct 163 ms 444776 KB Output is correct
57 Correct 181 ms 444760 KB Output is correct
58 Correct 164 ms 444428 KB Output is correct
59 Correct 177 ms 444496 KB Output is correct
60 Correct 153 ms 444232 KB Output is correct
61 Correct 925 ms 692836 KB Output is correct
62 Correct 1820 ms 979792 KB Output is correct
63 Correct 1793 ms 982296 KB Output is correct
64 Correct 1969 ms 982612 KB Output is correct
65 Correct 633 ms 673540 KB Output is correct
66 Correct 1095 ms 881748 KB Output is correct
67 Correct 1185 ms 909144 KB Output is correct
68 Correct 153 ms 444244 KB Output is correct
69 Correct 159 ms 444244 KB Output is correct
70 Correct 155 ms 444496 KB Output is correct
71 Correct 150 ms 444244 KB Output is correct
72 Correct 160 ms 444224 KB Output is correct
73 Runtime error 2116 ms 1048580 KB Memory limit exceeded
74 Halted 0 ms 0 KB -