Submission #1034901

# Submission time Handle Problem Language Result Execution time Memory
1034901 2024-07-25T20:53:00 Z amirhoseinfar1385 Rectangles (IOI19_rect) C++17
72 / 100
1849 ms 1048576 KB
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=2500+10;
int all[maxn][maxn],vis[maxn][maxn],tp[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 pre(){
	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++){
		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));
		}
	}
}


void calq(){
	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 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(){
	pre();
	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;
}
# Verdict Execution time Memory Grader output
1 Correct 159 ms 444244 KB Output is correct
2 Correct 157 ms 444496 KB Output is correct
3 Correct 161 ms 444676 KB Output is correct
4 Correct 150 ms 444500 KB Output is correct
5 Correct 146 ms 444496 KB Output is correct
6 Correct 152 ms 444500 KB Output is correct
7 Correct 148 ms 444496 KB Output is correct
8 Correct 150 ms 444240 KB Output is correct
9 Correct 150 ms 444500 KB Output is correct
10 Correct 154 ms 444496 KB Output is correct
11 Correct 148 ms 444676 KB Output is correct
12 Correct 151 ms 444664 KB Output is correct
13 Correct 149 ms 444240 KB Output is correct
14 Correct 154 ms 444352 KB Output is correct
15 Correct 141 ms 444240 KB Output is correct
16 Correct 153 ms 444244 KB Output is correct
17 Correct 163 ms 444140 KB Output is correct
18 Correct 146 ms 444240 KB Output is correct
19 Correct 154 ms 444524 KB Output is correct
20 Correct 154 ms 444244 KB Output is correct
21 Correct 145 ms 444240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 444244 KB Output is correct
2 Correct 157 ms 444496 KB Output is correct
3 Correct 161 ms 444676 KB Output is correct
4 Correct 150 ms 444500 KB Output is correct
5 Correct 146 ms 444496 KB Output is correct
6 Correct 152 ms 444500 KB Output is correct
7 Correct 148 ms 444496 KB Output is correct
8 Correct 150 ms 444240 KB Output is correct
9 Correct 150 ms 444500 KB Output is correct
10 Correct 154 ms 444496 KB Output is correct
11 Correct 148 ms 444676 KB Output is correct
12 Correct 151 ms 444664 KB Output is correct
13 Correct 149 ms 444240 KB Output is correct
14 Correct 154 ms 444352 KB Output is correct
15 Correct 141 ms 444240 KB Output is correct
16 Correct 153 ms 444244 KB Output is correct
17 Correct 163 ms 444140 KB Output is correct
18 Correct 146 ms 444240 KB Output is correct
19 Correct 154 ms 444524 KB Output is correct
20 Correct 154 ms 444244 KB Output is correct
21 Correct 145 ms 444240 KB Output is correct
22 Correct 150 ms 445524 KB Output is correct
23 Correct 155 ms 445520 KB Output is correct
24 Correct 153 ms 445776 KB Output is correct
25 Correct 162 ms 445392 KB Output is correct
26 Correct 156 ms 445404 KB Output is correct
27 Correct 166 ms 445508 KB Output is correct
28 Correct 156 ms 445428 KB Output is correct
29 Correct 161 ms 445272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 444244 KB Output is correct
2 Correct 157 ms 444496 KB Output is correct
3 Correct 161 ms 444676 KB Output is correct
4 Correct 150 ms 444500 KB Output is correct
5 Correct 146 ms 444496 KB Output is correct
6 Correct 152 ms 444500 KB Output is correct
7 Correct 148 ms 444496 KB Output is correct
8 Correct 150 ms 444240 KB Output is correct
9 Correct 150 ms 444500 KB Output is correct
10 Correct 154 ms 444496 KB Output is correct
11 Correct 148 ms 444676 KB Output is correct
12 Correct 151 ms 444664 KB Output is correct
13 Correct 149 ms 444240 KB Output is correct
14 Correct 154 ms 444352 KB Output is correct
15 Correct 141 ms 444240 KB Output is correct
16 Correct 153 ms 444244 KB Output is correct
17 Correct 150 ms 445524 KB Output is correct
18 Correct 155 ms 445520 KB Output is correct
19 Correct 153 ms 445776 KB Output is correct
20 Correct 162 ms 445392 KB Output is correct
21 Correct 156 ms 445404 KB Output is correct
22 Correct 166 ms 445508 KB Output is correct
23 Correct 156 ms 445428 KB Output is correct
24 Correct 161 ms 445272 KB Output is correct
25 Correct 163 ms 444140 KB Output is correct
26 Correct 146 ms 444240 KB Output is correct
27 Correct 154 ms 444524 KB Output is correct
28 Correct 154 ms 444244 KB Output is correct
29 Correct 145 ms 444240 KB Output is correct
30 Correct 156 ms 450460 KB Output is correct
31 Correct 167 ms 450384 KB Output is correct
32 Correct 162 ms 450388 KB Output is correct
33 Correct 151 ms 449360 KB Output is correct
34 Correct 171 ms 449616 KB Output is correct
35 Correct 169 ms 449684 KB Output is correct
36 Correct 179 ms 449616 KB Output is correct
37 Correct 161 ms 449616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 444244 KB Output is correct
2 Correct 157 ms 444496 KB Output is correct
3 Correct 161 ms 444676 KB Output is correct
4 Correct 150 ms 444500 KB Output is correct
5 Correct 146 ms 444496 KB Output is correct
6 Correct 152 ms 444500 KB Output is correct
7 Correct 148 ms 444496 KB Output is correct
8 Correct 150 ms 444240 KB Output is correct
9 Correct 150 ms 444500 KB Output is correct
10 Correct 154 ms 444496 KB Output is correct
11 Correct 148 ms 444676 KB Output is correct
12 Correct 151 ms 444664 KB Output is correct
13 Correct 149 ms 444240 KB Output is correct
14 Correct 154 ms 444352 KB Output is correct
15 Correct 141 ms 444240 KB Output is correct
16 Correct 153 ms 444244 KB Output is correct
17 Correct 150 ms 445524 KB Output is correct
18 Correct 155 ms 445520 KB Output is correct
19 Correct 153 ms 445776 KB Output is correct
20 Correct 162 ms 445392 KB Output is correct
21 Correct 156 ms 445404 KB Output is correct
22 Correct 166 ms 445508 KB Output is correct
23 Correct 156 ms 445428 KB Output is correct
24 Correct 161 ms 445272 KB Output is correct
25 Correct 156 ms 450460 KB Output is correct
26 Correct 167 ms 450384 KB Output is correct
27 Correct 162 ms 450388 KB Output is correct
28 Correct 151 ms 449360 KB Output is correct
29 Correct 171 ms 449616 KB Output is correct
30 Correct 169 ms 449684 KB Output is correct
31 Correct 179 ms 449616 KB Output is correct
32 Correct 161 ms 449616 KB Output is correct
33 Correct 163 ms 444140 KB Output is correct
34 Correct 146 ms 444240 KB Output is correct
35 Correct 154 ms 444524 KB Output is correct
36 Correct 154 ms 444244 KB Output is correct
37 Correct 145 ms 444240 KB Output is correct
38 Correct 242 ms 496300 KB Output is correct
39 Correct 249 ms 494072 KB Output is correct
40 Correct 232 ms 493932 KB Output is correct
41 Correct 238 ms 491600 KB Output is correct
42 Correct 264 ms 506196 KB Output is correct
43 Correct 251 ms 506104 KB Output is correct
44 Correct 253 ms 506196 KB Output is correct
45 Correct 265 ms 502300 KB Output is correct
46 Correct 236 ms 492112 KB Output is correct
47 Correct 272 ms 493392 KB Output is correct
48 Correct 327 ms 498260 KB Output is correct
49 Correct 344 ms 498260 KB Output is correct
50 Correct 240 ms 473940 KB Output is correct
51 Correct 237 ms 471156 KB Output is correct
52 Correct 345 ms 497492 KB Output is correct
53 Correct 332 ms 497488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 445012 KB Output is correct
2 Correct 144 ms 444752 KB Output is correct
3 Correct 147 ms 444752 KB Output is correct
4 Correct 147 ms 444240 KB Output is correct
5 Correct 156 ms 444756 KB Output is correct
6 Correct 143 ms 444752 KB Output is correct
7 Correct 152 ms 444752 KB Output is correct
8 Correct 161 ms 444756 KB Output is correct
9 Correct 151 ms 444756 KB Output is correct
10 Correct 158 ms 444244 KB Output is correct
11 Correct 153 ms 444500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 444140 KB Output is correct
2 Correct 146 ms 444240 KB Output is correct
3 Correct 154 ms 444524 KB Output is correct
4 Correct 154 ms 444244 KB Output is correct
5 Correct 145 ms 444240 KB Output is correct
6 Correct 154 ms 444240 KB Output is correct
7 Correct 854 ms 692556 KB Output is correct
8 Correct 1761 ms 979816 KB Output is correct
9 Correct 1776 ms 982360 KB Output is correct
10 Correct 1794 ms 982612 KB Output is correct
11 Correct 738 ms 673776 KB Output is correct
12 Correct 1124 ms 881804 KB Output is correct
13 Correct 1042 ms 909148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 444244 KB Output is correct
2 Correct 157 ms 444496 KB Output is correct
3 Correct 161 ms 444676 KB Output is correct
4 Correct 150 ms 444500 KB Output is correct
5 Correct 146 ms 444496 KB Output is correct
6 Correct 152 ms 444500 KB Output is correct
7 Correct 148 ms 444496 KB Output is correct
8 Correct 150 ms 444240 KB Output is correct
9 Correct 150 ms 444500 KB Output is correct
10 Correct 154 ms 444496 KB Output is correct
11 Correct 148 ms 444676 KB Output is correct
12 Correct 151 ms 444664 KB Output is correct
13 Correct 149 ms 444240 KB Output is correct
14 Correct 154 ms 444352 KB Output is correct
15 Correct 141 ms 444240 KB Output is correct
16 Correct 153 ms 444244 KB Output is correct
17 Correct 150 ms 445524 KB Output is correct
18 Correct 155 ms 445520 KB Output is correct
19 Correct 153 ms 445776 KB Output is correct
20 Correct 162 ms 445392 KB Output is correct
21 Correct 156 ms 445404 KB Output is correct
22 Correct 166 ms 445508 KB Output is correct
23 Correct 156 ms 445428 KB Output is correct
24 Correct 161 ms 445272 KB Output is correct
25 Correct 156 ms 450460 KB Output is correct
26 Correct 167 ms 450384 KB Output is correct
27 Correct 162 ms 450388 KB Output is correct
28 Correct 151 ms 449360 KB Output is correct
29 Correct 171 ms 449616 KB Output is correct
30 Correct 169 ms 449684 KB Output is correct
31 Correct 179 ms 449616 KB Output is correct
32 Correct 161 ms 449616 KB Output is correct
33 Correct 242 ms 496300 KB Output is correct
34 Correct 249 ms 494072 KB Output is correct
35 Correct 232 ms 493932 KB Output is correct
36 Correct 238 ms 491600 KB Output is correct
37 Correct 264 ms 506196 KB Output is correct
38 Correct 251 ms 506104 KB Output is correct
39 Correct 253 ms 506196 KB Output is correct
40 Correct 265 ms 502300 KB Output is correct
41 Correct 236 ms 492112 KB Output is correct
42 Correct 272 ms 493392 KB Output is correct
43 Correct 327 ms 498260 KB Output is correct
44 Correct 344 ms 498260 KB Output is correct
45 Correct 240 ms 473940 KB Output is correct
46 Correct 237 ms 471156 KB Output is correct
47 Correct 345 ms 497492 KB Output is correct
48 Correct 332 ms 497488 KB Output is correct
49 Correct 154 ms 445012 KB Output is correct
50 Correct 144 ms 444752 KB Output is correct
51 Correct 147 ms 444752 KB Output is correct
52 Correct 147 ms 444240 KB Output is correct
53 Correct 156 ms 444756 KB Output is correct
54 Correct 143 ms 444752 KB Output is correct
55 Correct 152 ms 444752 KB Output is correct
56 Correct 161 ms 444756 KB Output is correct
57 Correct 151 ms 444756 KB Output is correct
58 Correct 158 ms 444244 KB Output is correct
59 Correct 153 ms 444500 KB Output is correct
60 Correct 154 ms 444240 KB Output is correct
61 Correct 854 ms 692556 KB Output is correct
62 Correct 1761 ms 979816 KB Output is correct
63 Correct 1776 ms 982360 KB Output is correct
64 Correct 1794 ms 982612 KB Output is correct
65 Correct 738 ms 673776 KB Output is correct
66 Correct 1124 ms 881804 KB Output is correct
67 Correct 1042 ms 909148 KB Output is correct
68 Correct 163 ms 444140 KB Output is correct
69 Correct 146 ms 444240 KB Output is correct
70 Correct 154 ms 444524 KB Output is correct
71 Correct 154 ms 444244 KB Output is correct
72 Correct 145 ms 444240 KB Output is correct
73 Correct 1780 ms 1048576 KB Output is correct
74 Correct 1849 ms 1032576 KB Output is correct
75 Correct 1412 ms 998036 KB Output is correct
76 Correct 1419 ms 976920 KB Output is correct
77 Runtime error 963 ms 1048576 KB Execution killed with signal 9
78 Halted 0 ms 0 KB -