답안 #527816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527816 2022-02-18T12:45:45 Z Koosha_mv Sterilizing Spray (JOI15_sterilizing) C++14
0 / 100
5000 ms 4240 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=5e5+99;

int n,q,k,a[N],Sum[N],Max[N];

void merge(int id){
	Sum[id]=Sum[id<<1]+Sum[id<<1|1];
	Max[id]=max(Max[id<<1],Max[id<<1|1]);
}
void build(int id=1,int l=1,int r=n+1){
	if(l+1==r){
		Sum[id]=a[l];
		Max[id]=a[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(id<<1,l,mid);
	build(id<<1|1,mid,r);
	merge(id);
}
void change(int x,int val,int id=1,int l=1,int r=n+1){
	if(r<=x || x<l) return ;
	if(l+1==r){
		Sum[id]=val;
		Max[id]=val;
		return ;
	}
	int mid=(l+r)>>1;
	change(x,val,id<<1,l,mid);
	change(x,val,id<<1|1,mid,r);
	merge(id);
}
int get(int L,int R,int id=1,int l=1,int r=n+1){
	if(r<=L || R<=l) return 0;
	if(L<=l && r<=R){
		return Sum[id];
	}
	int mid=(l+r)>>1;
	return get(L,R,id<<1,l,mid)+get(L,R,id<<1|1,mid,r);
}
void spray(int L,int R,int id=1,int l=1,int r=n+1){
	if(Max[id]==0 || r<=L || R<=l) return ;
	if(l+1==r){
		Sum[id]/=k;
		Max[id]/=k;
		return ;
	}
	int mid=(l+r)>>1;
	spray(L,R,id<<1,l,mid);
	spray(L,R,id<<1|1,mid,r);
	merge(id);
}

int main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>q>>k;
	f(i,1,n+1) cin>>a[i];
	build();
	f(i,0,q){
		int type,l,r;
		cin>>type>>l>>r;
		if(type==1){
			change(l,r);
		}
		if(type==2){
			spray(l,r+1);
		}
		if(type==3){
			cout<<get(l,r+1)<<'\n';
		}
	}
}
/*
5 2 3
1 5 8 1 3
2 3 5
3 2 5
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5059 ms 3292 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 852 KB Output is correct
2 Correct 11 ms 1812 KB Output is correct
3 Correct 14 ms 1848 KB Output is correct
4 Correct 40 ms 2200 KB Output is correct
5 Correct 49 ms 4180 KB Output is correct
6 Correct 55 ms 4240 KB Output is correct
7 Execution timed out 5045 ms 3952 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 77 ms 3224 KB Output isn't correct
2 Halted 0 ms 0 KB -