Submission #68370

# Submission time Handle Problem Language Result Execution time Memory
68370 2018-08-16T21:15:21 Z Kerim Sterilizing Spray (JOI15_sterilizing) C++17
80 / 100
5000 ms 8220 KB
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll sum[MAXN<<2];
int mx[MAXN<<2],arr[MAXN],k;
void build(int nd,int x,int y){
	if(x==y){
		sum[nd]=mx[nd]=arr[x];
		return;
	}
	int mid=(x+y)>>1;
	build(nd<<1,x,mid);
	build(nd<<1|1,mid+1,y);
	sum[nd]=sum[nd<<1]+sum[nd<<1|1];
	mx[nd]=max(mx[nd<<1],mx[nd<<1|1]);
}
void upd(int p,int v,int nd,int x,int y){
	if(x==y){
		sum[nd]=mx[nd]=v;
		return;
	}
	int mid=(x+y)>>1;
	if(p<=mid)
		upd(p,v,nd<<1,x,mid);
	else	
		upd(p,v,nd<<1|1,mid+1,y);
	sum[nd]=sum[nd<<1]+sum[nd<<1|1];
	mx[nd]=max(mx[nd<<1],mx[nd<<1|1]);
}
void inc(int l,int r,int nd,int x,int y){
	if(l>y or x>r or !mx[nd])
		return;
	if(x==y){
		sum[nd]/=k;
		mx[nd]/=k;
		return;
	}	
	int mid=(x+y)>>1;
	inc(l,r,nd<<1,x,mid);
	inc(l,r,nd<<1|1,mid+1,y);
	sum[nd]=sum[nd<<1]+sum[nd<<1|1];
	mx[nd]=max(mx[nd<<1],mx[nd<<1|1]);
}
ll tap(int l,int r,int nd,int x,int y){
	if(l>y or x>r)
		return 0;
	if(l<=x and y<=r)
		return sum[nd];
	int mid=(x+y)>>1;
	return tap(l,r,nd<<1,x,mid)+tap(l,r,nd<<1|1,mid+1,y);	
}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,q;
    scanf("%d%d%d",&n,&q,&k);
    for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	build(1,1,n);
	while(q--){
		int t,l,r;
		scanf("%d%d%d",&t,&l,&r);
		if(t==1)
			upd(l,r,1,1,n);
		else if(t==2)
			inc(l,r,1,1,n);
		else
			printf("%lld\n",tap(l,r,1,1,n));
	}	
	return 0;
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&q,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
sterilizing.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",arr+i);
   ~~~~~^~~~~~~~~~~~
sterilizing.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&t,&l,&r);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 520 KB Output is correct
3 Correct 4 ms 636 KB Output is correct
4 Correct 8 ms 728 KB Output is correct
5 Correct 8 ms 828 KB Output is correct
6 Correct 7 ms 1044 KB Output is correct
7 Correct 7 ms 1124 KB Output is correct
8 Correct 7 ms 1128 KB Output is correct
9 Correct 8 ms 1196 KB Output is correct
10 Correct 6 ms 1280 KB Output is correct
11 Correct 6 ms 1352 KB Output is correct
12 Correct 7 ms 1420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5079 ms 4724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 4724 KB Output is correct
2 Correct 17 ms 4996 KB Output is correct
3 Correct 28 ms 5568 KB Output is correct
4 Correct 72 ms 5568 KB Output is correct
5 Correct 94 ms 7696 KB Output is correct
6 Correct 92 ms 7744 KB Output is correct
7 Execution timed out 5025 ms 8144 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 127 ms 8144 KB Output is correct
2 Correct 125 ms 8144 KB Output is correct
3 Correct 145 ms 8144 KB Output is correct
4 Correct 171 ms 8144 KB Output is correct
5 Correct 241 ms 8144 KB Output is correct
6 Correct 223 ms 8220 KB Output is correct
7 Correct 189 ms 8220 KB Output is correct
8 Correct 281 ms 8220 KB Output is correct
9 Correct 292 ms 8220 KB Output is correct
10 Correct 277 ms 8220 KB Output is correct
11 Correct 196 ms 8220 KB Output is correct
12 Correct 325 ms 8220 KB Output is correct