답안 #1034896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034896 2024-07-25T20:50:06 Z amirhoseinfar1385 Rectangles (IOI19_rect) C++17
컴파일 오류
0 ms 0 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>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 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++){
		vector<pair<int,int>>allv;
		for(int j=1;j<=m;j++){
			while((int)allv.size()>0&&allv.back().first<all[i][j]){
				auto x=allv.back().second;
				dpp[x][j]=dpp[x][j-1]+1;
				allq[i+1][j+1].push_back(make_pair((x-i-1),j-dpp[x][j]));
				allv.pop_back();
			}
			if((int)allv.size()>0){
				auto x=allv.back().second;
				dpp[x][j]=dpp[x][j-1]+1;
				allq[i+1][j+1].push_back(make_pair((x-i-1),j-dpp[x][j]));
			}
			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(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;
}

Compilation message

rect.cpp: In function 'void calq()':
rect.cpp:117:15: error: 'alll' was not declared in this scope; did you mean 'allq'?
  117 |    for(auto x:alll[i][j]){
      |               ^~~~
      |               allq
rect.cpp:127:15: error: 'alll' was not declared in this scope; did you mean 'allq'?
  127 |    for(auto x:alll[i][j]){
      |               ^~~~
      |               allq