# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99475 | rzbt | Divide and conquer (IZhO14_divide) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;
using namespace std;
int seg[MAXN];
int lazy[MAXN];
int dodaj(int l,int d,int tl,int td,int k){
if(lazy[k]){
if(l!=d){
lazy[k+k]+=lazy[k];
lazy[k+k+1]+=lazy[k];
}
lazy[k]=0;
}
if(l>td || d<tl)return -1;
if(l>=tl && d<=td){
return seg[k];
}
int mid=(l+d)/2;
return max( dobij(l,mid,tl,td,k+k,x) , dobij(mid+1,d,tl,td,k+k+1) );
}
void dobij(int l,int d,int tl,int td,int k,int x){
if(lazy[k]){
if(l!=d){
lazy[k+k]+=lazy[k];
lazy[k+k+1]+=lazy[k];
}
lazy[k]=0;
}
if(l>td || d<tl)return;
if(l>=tl && d<=td){
seg[k]+=(d-l+1)*x;
lazy[k]=x;
if(l!=d){
lazy[k+k]+=lazy[k];
lazy[k+k+1]+=lazy[k];
}
lazy[k]=0;
}
int mid=(l+d)/2;
dodaj(l,mid,tl,td,k+k,x);
dodaj(mid+1,d,tl,td,k+k+1,x);
}
int n;
int main()
{
scanf("%d", &n);
int x,z,e,px;
scanf("%d %d %d", &x, &z, &e);
dodaj()
return 0;
}