QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287859 | #3850. DJ Darko | LaStataleBlue | ML | 0ms | 0kb | C++23 | 2.8kb | 2023-12-21 04:19:52 | 2023-12-21 04:19:53 |
answer
#include<bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
#define _mid (_l+_r)/2
struct SegmentTree{
long long val,lazy;
SegmentTree *left,*right;
static SegmentTree* newSeg(long long val);
void checkchild(){
if(val!=INF){
if(left)delete left;
if(right)delete right;
left = newSeg(val-lazy);
right = newSeg(val-lazy);
val=INF;
}
}
void checklazy(){
if(lazy!=0){
if(left->val!=INF)left->val+=lazy;
left->lazy+=lazy;
if(right->val!=INF)right->val+=lazy;
right->lazy+=lazy;
lazy=0;
}
}
void query(int l,int r,int _l,int _r,vector<array<long long,3>> &v){
if(_r<l || _l>r)return;
if(_l>=l && _r<=r && val!=INF){
v.push_back({val,_l,_r});
return;
}
checkchild();
checklazy();
left->query(l,r,_l,_mid,v);
right->query(l,r,_mid+1,_r,v);
}
void update2(int l,int r,long long vval,int _l,int _r){
if(_r<l || _l>r)return;
if(_l>=l && _r<=r){
if(val!=INF)val+=vval;
lazy+=vval;
return;
}
checkchild();
checklazy();
left->update2(l,r,vval,_l,_mid);
right->update2(l,r,vval,_mid+1,_r);
}
void update(int l,int r,long long vval,int _l,int _r){
if(_r<l || _l>r)return;
if(_l>=l && _r<=r){
val = vval;
lazy = 0;
left = right = nullptr;
return;
}
checkchild();
checklazy();
left->update(l,r,vval,_l,_mid);
right->update(l,r,vval,_mid+1,_r);
}
};
//const int VAL = 7'500'000;
//SegmentTree vett[VAL];
//int cc = 0;
SegmentTree* SegmentTree::newSeg(long long val){
//if(cc==VAL)exit(0);
//int ind = cc++;
auto res = new SegmentTree();
res->val=val;
res->lazy=0;
res->left=res->right=nullptr;
return res;
//vett[ind].val=val;
//vett[ind].lazy=0;
//vett[ind].left = vett[ind].right = nullptr;
//return &vett[ind];
}
#undef _mid
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,q;
cin>>n>>q;
SegmentTree *ds = SegmentTree::newSeg(0);
vector<int> a(n+1);
vector<long long> b(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
ds->update(i,i,a[i],1,n);
}
for(int i=1;i<=n;i++){
cin>>b[i];
b[i]+=b[i-1];
}
for(int i=0;i<q;i++){
int t;
cin>>t;
if(t==1){
int l,r,x;
cin>>l>>r>>x;
ds->update2(l,r,x,1,n);
}else{
int l,r;
cin>>l>>r;
vector<array<long long,3>> res;
ds->query(l,r,1,n,res);
sort(res.begin(),res.end());
long long sum=0;
for(auto &i : res){
//cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<" ecco\n";
i[1]=b[i[2]]-b[i[1]-1];
sum+=i[1];
}
long long curr=0;
long long ans;
for(auto [a,b,c] : res){
curr+=b;
if(curr>=(sum+1)/2){
ans=a;
break;
}
}
cout<<ans<<"\n";
ds->update(l,r,ans,1,n);
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
200000 200000 185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...
output:
462406736 1749348519 1749348519 467651597 874061694 874061694 874061694 874061694 -1521749 874061694 -893932302 -425504259 -425504259 332034115 332034115 86195778 86195778 86195778 86195778 86195778 -425504259 -165776398 -165776398 -165776398 -916781043 -254293799 -254293799 -254293799 -254293799 -8...