답안 #646989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646989 2022-10-01T09:58:26 Z jamielim Fancy Fence (CEOI20_fancyfence) C++14
13 / 100
63 ms 19436 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n;
int h[100005],w[100005];

inline ll choose2(ll x){
	return ((x)*(x-1)/2)%MOD;
}

struct node{
	int s,e,m;
	ll ht,wd,val;
	ll lzht;
	node *l,*r;
	node(int S,int E){
		s=S;e=E;m=(s+e)/2;
		lzht=-1;
		if(s==e){
			ht=h[s];
			wd=w[s];
			val=(wd*choose2(ht+1))%MOD;
		}else{
			l=new node(s,m);
			r=new node(m+1,e);
			ht=min(l->ht,r->ht);
			wd=l->wd+r->wd;
			val=l->val+r->val;
		}
	}
	void laze(){
		if(lzht==-1)return;
		if(s!=e){
			l->lzht=lzht;
			r->lzht=lzht;
		}
		ht=lzht;
		lzht=-1;
		val=(wd*choose2(ht+1))%MOD;
	}
	void upd(int x,int y,ll v){ // set height to be v for indices in [x,y]
		if(y<s||x>e||x>y)return;
		//printf("%d %d %lld\n",x,y,v);
		if(x<=s&&e<=y){
			lzht=v;
			laze();
			//printf("u %d %d %lld\n",s,e,val);
			return;
		}
		laze();
		if(y<=m)l->upd(x,y,v);
		else if(x>m)r->upd(x,y,v);
		else l->upd(x,m,v),r->upd(m+1,y,v);
		l->laze();r->laze();
		ht=min(l->ht,r->ht);
		val=(l->val+r->val)%MOD;
		//printf("u %d %d %lld\n",s,e,val);
	}
	ll qry(int x){ // sum of wd*((ht+1)C2) for indices <=x
		if(x<s)return 0;
		if(e<=x)return val;
		if(x<=m)return l->qry(x);
		return (l->val+r->qry(x))%MOD;
	}
}*root;

int main(){
	//freopen("sample/input1.txt","r",stdin);
	scanf("%d",&n);
	vector<int> v;
	for(int i=0;i<n;i++){
		scanf("%d",&h[i]);
		v.pb(h[i]);
	}
	for(int i=0;i<n;i++)scanf("%d",&w[i]);
	root=new node(0,n-1);
	ll ans=0;
	vector<ii> stk;
	stk.pb(-1,-1);
	for(int i=0;i<n;i++){
		// find leftmost value that is > h[i] and index <i
		int x=i;
		while(stk.back().fi>h[i]){
			x=stk.back().se;
			stk.pop_back();
		}
		stk.pb(h[i],i);
		root->upd(x,i-1,h[i]);
		
		ll cur=(root->qry(i-1))*(ll)(w[i]);
		cur%=MOD;
		ans+=cur; // left side is strictly from previous block, right side is (,] of current block
		ans%=MOD;
		ans+=((choose2(h[i]+1))*(choose2(w[i]+1)))%MOD; // left side is within current block
		ans%=MOD;
		//printf("a %lld\n",ans);
	}
	printf("%lld",ans%MOD);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
fancyfence.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |   scanf("%d",&h[i]);
      |   ~~~~~^~~~~~~~~~~~
fancyfence.cpp:90:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |  for(int i=0;i<n;i++)scanf("%d",&w[i]);
      |                      ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 23 ms 9696 KB Output is correct
4 Correct 45 ms 19436 KB Output is correct
5 Correct 47 ms 19008 KB Output is correct
6 Correct 63 ms 18420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -