結果
| 問題 | No.1074 増殖 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-06-05 22:47:05 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 53 ms / 2,000 ms | 
| コード長 | 1,111 bytes | 
| コンパイル時間 | 3,325 ms | 
| コンパイル使用メモリ | 205,416 KB | 
| 最終ジャッジ日時 | 2025-01-10 22:49:32 | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:39:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         rep(i,n) scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
vector<int> solve(vector<int> X,vector<int> Y){
	int n=X.size();
	set<pair<int,int>> S={{0,INF},{INF,0}};
	vector<int> res(n);
	rep(i,n){
		if(i>0) res[i]=res[i-1];
		auto it=S.lower_bound({X[i],Y[i]});
		int x1,y1; tie(x1,y1)=*it;
		if(Y[i]<=y1) continue;
		--it;
		int x2,y2; tie(x2,y2)=*it;
		res[i]-=(X[i]-x2)*y1;
		while(y2<=Y[i]){
			it=--S.erase(it);
			x1=x2; y1=y2;
			tie(x2,y2)=*it;
			res[i]-=(x1-x2)*y1;
		}
		res[i]+=(X[i]-it->first)*Y[i];
		S.emplace(X[i],Y[i]);
	}
	return res;
}
int main(){
	int n; scanf("%d",&n);
	vector<int> x1(n),y1(n),x2(n),y2(n);
	rep(i,n) scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
	vector<int> ans(n);
	rep(t,4){
		vector<int> X(n),Y(n);
		rep(i,n){
			if(t==0) X[i]= x2[i], Y[i]= y2[i];
			if(t==1) X[i]=-x1[i], Y[i]= y2[i];
			if(t==2) X[i]=-x1[i], Y[i]=-y1[i];
			if(t==3) X[i]= x2[i], Y[i]=-y1[i];
		}
		auto res=solve(X,Y);
		rep(i,n) ans[i]+=res[i];
	}
	for(int i=n-1;i>0;i--) ans[i]-=ans[i-1];
	rep(i,n) printf("%d\n",ans[i]);
	return 0;
}
            
            
            
        