Submission #1034902

# Submission time Handle Problem Language Result Execution time Memory
1034902 2024-07-25T20:53:43 Z amirhoseinfar1385 Rectangles (IOI19_rect) C++17
72 / 100
1874 ms 1048576 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 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 155 ms 444244 KB Output is correct
2 Correct 171 ms 444496 KB Output is correct
3 Correct 155 ms 444500 KB Output is correct
4 Correct 157 ms 444500 KB Output is correct
5 Correct 174 ms 444500 KB Output is correct
6 Correct 168 ms 444504 KB Output is correct
7 Correct 168 ms 444500 KB Output is correct
8 Correct 155 ms 444244 KB Output is correct
9 Correct 159 ms 444612 KB Output is correct
10 Correct 154 ms 444584 KB Output is correct
11 Correct 172 ms 444472 KB Output is correct
12 Correct 165 ms 444496 KB Output is correct
13 Correct 159 ms 444240 KB Output is correct
14 Correct 159 ms 444156 KB Output is correct
15 Correct 168 ms 444256 KB Output is correct
16 Correct 154 ms 444144 KB Output is correct
17 Correct 157 ms 444228 KB Output is correct
18 Correct 164 ms 444240 KB Output is correct
19 Correct 163 ms 444572 KB Output is correct
20 Correct 156 ms 444240 KB Output is correct
21 Correct 163 ms 444240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 444244 KB Output is correct
2 Correct 171 ms 444496 KB Output is correct
3 Correct 155 ms 444500 KB Output is correct
4 Correct 157 ms 444500 KB Output is correct
5 Correct 174 ms 444500 KB Output is correct
6 Correct 168 ms 444504 KB Output is correct
7 Correct 168 ms 444500 KB Output is correct
8 Correct 155 ms 444244 KB Output is correct
9 Correct 159 ms 444612 KB Output is correct
10 Correct 154 ms 444584 KB Output is correct
11 Correct 172 ms 444472 KB Output is correct
12 Correct 165 ms 444496 KB Output is correct
13 Correct 159 ms 444240 KB Output is correct
14 Correct 159 ms 444156 KB Output is correct
15 Correct 168 ms 444256 KB Output is correct
16 Correct 154 ms 444144 KB Output is correct
17 Correct 157 ms 444228 KB Output is correct
18 Correct 164 ms 444240 KB Output is correct
19 Correct 163 ms 444572 KB Output is correct
20 Correct 156 ms 444240 KB Output is correct
21 Correct 163 ms 444240 KB Output is correct
22 Correct 169 ms 445596 KB Output is correct
23 Correct 164 ms 445520 KB Output is correct
24 Correct 162 ms 445564 KB Output is correct
25 Correct 166 ms 445524 KB Output is correct
26 Correct 160 ms 445524 KB Output is correct
27 Correct 160 ms 445520 KB Output is correct
28 Correct 163 ms 445544 KB Output is correct
29 Correct 166 ms 445056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 444244 KB Output is correct
2 Correct 171 ms 444496 KB Output is correct
3 Correct 155 ms 444500 KB Output is correct
4 Correct 157 ms 444500 KB Output is correct
5 Correct 174 ms 444500 KB Output is correct
6 Correct 168 ms 444504 KB Output is correct
7 Correct 168 ms 444500 KB Output is correct
8 Correct 155 ms 444244 KB Output is correct
9 Correct 159 ms 444612 KB Output is correct
10 Correct 154 ms 444584 KB Output is correct
11 Correct 172 ms 444472 KB Output is correct
12 Correct 165 ms 444496 KB Output is correct
13 Correct 159 ms 444240 KB Output is correct
14 Correct 159 ms 444156 KB Output is correct
15 Correct 168 ms 444256 KB Output is correct
16 Correct 154 ms 444144 KB Output is correct
17 Correct 169 ms 445596 KB Output is correct
18 Correct 164 ms 445520 KB Output is correct
19 Correct 162 ms 445564 KB Output is correct
20 Correct 166 ms 445524 KB Output is correct
21 Correct 160 ms 445524 KB Output is correct
22 Correct 160 ms 445520 KB Output is correct
23 Correct 163 ms 445544 KB Output is correct
24 Correct 166 ms 445056 KB Output is correct
25 Correct 157 ms 444228 KB Output is correct
26 Correct 164 ms 444240 KB Output is correct
27 Correct 163 ms 444572 KB Output is correct
28 Correct 156 ms 444240 KB Output is correct
29 Correct 163 ms 444240 KB Output is correct
30 Correct 171 ms 450388 KB Output is correct
31 Correct 171 ms 450384 KB Output is correct
32 Correct 181 ms 450444 KB Output is correct
33 Correct 164 ms 449420 KB Output is correct
34 Correct 180 ms 449616 KB Output is correct
35 Correct 178 ms 449708 KB Output is correct
36 Correct 169 ms 449620 KB Output is correct
37 Correct 176 ms 449616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 444244 KB Output is correct
2 Correct 171 ms 444496 KB Output is correct
3 Correct 155 ms 444500 KB Output is correct
4 Correct 157 ms 444500 KB Output is correct
5 Correct 174 ms 444500 KB Output is correct
6 Correct 168 ms 444504 KB Output is correct
7 Correct 168 ms 444500 KB Output is correct
8 Correct 155 ms 444244 KB Output is correct
9 Correct 159 ms 444612 KB Output is correct
10 Correct 154 ms 444584 KB Output is correct
11 Correct 172 ms 444472 KB Output is correct
12 Correct 165 ms 444496 KB Output is correct
13 Correct 159 ms 444240 KB Output is correct
14 Correct 159 ms 444156 KB Output is correct
15 Correct 168 ms 444256 KB Output is correct
16 Correct 154 ms 444144 KB Output is correct
17 Correct 169 ms 445596 KB Output is correct
18 Correct 164 ms 445520 KB Output is correct
19 Correct 162 ms 445564 KB Output is correct
20 Correct 166 ms 445524 KB Output is correct
21 Correct 160 ms 445524 KB Output is correct
22 Correct 160 ms 445520 KB Output is correct
23 Correct 163 ms 445544 KB Output is correct
24 Correct 166 ms 445056 KB Output is correct
25 Correct 171 ms 450388 KB Output is correct
26 Correct 171 ms 450384 KB Output is correct
27 Correct 181 ms 450444 KB Output is correct
28 Correct 164 ms 449420 KB Output is correct
29 Correct 180 ms 449616 KB Output is correct
30 Correct 178 ms 449708 KB Output is correct
31 Correct 169 ms 449620 KB Output is correct
32 Correct 176 ms 449616 KB Output is correct
33 Correct 157 ms 444228 KB Output is correct
34 Correct 164 ms 444240 KB Output is correct
35 Correct 163 ms 444572 KB Output is correct
36 Correct 156 ms 444240 KB Output is correct
37 Correct 163 ms 444240 KB Output is correct
38 Correct 283 ms 496208 KB Output is correct
39 Correct 269 ms 493908 KB Output is correct
40 Correct 254 ms 494040 KB Output is correct
41 Correct 264 ms 491600 KB Output is correct
42 Correct 270 ms 506192 KB Output is correct
43 Correct 281 ms 506196 KB Output is correct
44 Correct 276 ms 506384 KB Output is correct
45 Correct 268 ms 502096 KB Output is correct
46 Correct 255 ms 492112 KB Output is correct
47 Correct 286 ms 493156 KB Output is correct
48 Correct 353 ms 498256 KB Output is correct
49 Correct 348 ms 498256 KB Output is correct
50 Correct 272 ms 474452 KB Output is correct
51 Correct 246 ms 471120 KB Output is correct
52 Correct 338 ms 497488 KB Output is correct
53 Correct 333 ms 497488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 445008 KB Output is correct
2 Correct 158 ms 444752 KB Output is correct
3 Correct 152 ms 444752 KB Output is correct
4 Correct 150 ms 444136 KB Output is correct
5 Correct 215 ms 444768 KB Output is correct
6 Correct 162 ms 444752 KB Output is correct
7 Correct 165 ms 444676 KB Output is correct
8 Correct 157 ms 444756 KB Output is correct
9 Correct 164 ms 445012 KB Output is correct
10 Correct 159 ms 444456 KB Output is correct
11 Correct 156 ms 444496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 444228 KB Output is correct
2 Correct 164 ms 444240 KB Output is correct
3 Correct 163 ms 444572 KB Output is correct
4 Correct 156 ms 444240 KB Output is correct
5 Correct 163 ms 444240 KB Output is correct
6 Correct 160 ms 444348 KB Output is correct
7 Correct 895 ms 692648 KB Output is correct
8 Correct 1807 ms 979836 KB Output is correct
9 Correct 1874 ms 982468 KB Output is correct
10 Correct 1824 ms 982864 KB Output is correct
11 Correct 562 ms 673752 KB Output is correct
12 Correct 977 ms 881748 KB Output is correct
13 Correct 1020 ms 909160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 444244 KB Output is correct
2 Correct 171 ms 444496 KB Output is correct
3 Correct 155 ms 444500 KB Output is correct
4 Correct 157 ms 444500 KB Output is correct
5 Correct 174 ms 444500 KB Output is correct
6 Correct 168 ms 444504 KB Output is correct
7 Correct 168 ms 444500 KB Output is correct
8 Correct 155 ms 444244 KB Output is correct
9 Correct 159 ms 444612 KB Output is correct
10 Correct 154 ms 444584 KB Output is correct
11 Correct 172 ms 444472 KB Output is correct
12 Correct 165 ms 444496 KB Output is correct
13 Correct 159 ms 444240 KB Output is correct
14 Correct 159 ms 444156 KB Output is correct
15 Correct 168 ms 444256 KB Output is correct
16 Correct 154 ms 444144 KB Output is correct
17 Correct 169 ms 445596 KB Output is correct
18 Correct 164 ms 445520 KB Output is correct
19 Correct 162 ms 445564 KB Output is correct
20 Correct 166 ms 445524 KB Output is correct
21 Correct 160 ms 445524 KB Output is correct
22 Correct 160 ms 445520 KB Output is correct
23 Correct 163 ms 445544 KB Output is correct
24 Correct 166 ms 445056 KB Output is correct
25 Correct 171 ms 450388 KB Output is correct
26 Correct 171 ms 450384 KB Output is correct
27 Correct 181 ms 450444 KB Output is correct
28 Correct 164 ms 449420 KB Output is correct
29 Correct 180 ms 449616 KB Output is correct
30 Correct 178 ms 449708 KB Output is correct
31 Correct 169 ms 449620 KB Output is correct
32 Correct 176 ms 449616 KB Output is correct
33 Correct 283 ms 496208 KB Output is correct
34 Correct 269 ms 493908 KB Output is correct
35 Correct 254 ms 494040 KB Output is correct
36 Correct 264 ms 491600 KB Output is correct
37 Correct 270 ms 506192 KB Output is correct
38 Correct 281 ms 506196 KB Output is correct
39 Correct 276 ms 506384 KB Output is correct
40 Correct 268 ms 502096 KB Output is correct
41 Correct 255 ms 492112 KB Output is correct
42 Correct 286 ms 493156 KB Output is correct
43 Correct 353 ms 498256 KB Output is correct
44 Correct 348 ms 498256 KB Output is correct
45 Correct 272 ms 474452 KB Output is correct
46 Correct 246 ms 471120 KB Output is correct
47 Correct 338 ms 497488 KB Output is correct
48 Correct 333 ms 497488 KB Output is correct
49 Correct 154 ms 445008 KB Output is correct
50 Correct 158 ms 444752 KB Output is correct
51 Correct 152 ms 444752 KB Output is correct
52 Correct 150 ms 444136 KB Output is correct
53 Correct 215 ms 444768 KB Output is correct
54 Correct 162 ms 444752 KB Output is correct
55 Correct 165 ms 444676 KB Output is correct
56 Correct 157 ms 444756 KB Output is correct
57 Correct 164 ms 445012 KB Output is correct
58 Correct 159 ms 444456 KB Output is correct
59 Correct 156 ms 444496 KB Output is correct
60 Correct 160 ms 444348 KB Output is correct
61 Correct 895 ms 692648 KB Output is correct
62 Correct 1807 ms 979836 KB Output is correct
63 Correct 1874 ms 982468 KB Output is correct
64 Correct 1824 ms 982864 KB Output is correct
65 Correct 562 ms 673752 KB Output is correct
66 Correct 977 ms 881748 KB Output is correct
67 Correct 1020 ms 909160 KB Output is correct
68 Correct 157 ms 444228 KB Output is correct
69 Correct 164 ms 444240 KB Output is correct
70 Correct 163 ms 444572 KB Output is correct
71 Correct 156 ms 444240 KB Output is correct
72 Correct 163 ms 444240 KB Output is correct
73 Correct 1748 ms 1048576 KB Output is correct
74 Correct 1833 ms 1017168 KB Output is correct
75 Correct 1384 ms 998060 KB Output is correct
76 Correct 1437 ms 976976 KB Output is correct
77 Runtime error 949 ms 1048576 KB Execution killed with signal 9
78 Halted 0 ms 0 KB -