QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197364 | #3850. DJ Darko | Suiseiseki | WA | 344ms | 21100kb | C++14 | 2.9kb | 2023-10-02 15:08:03 | 2023-10-02 15:08:03 |
Judging History
answer
#include <vector>
#include <cstdio>
#include <algorithm>
typedef long long ll;
const int Maxn=200000;
void read(int &a){
a=0;
char c=getchar();
while(c<'0'||c>'9'){
c=getchar();
}
while(c>='0'&&c<='9'){
a=a*10+c-'0';
c=getchar();
}
}
int n,q;
int a[Maxn+5],b[Maxn+5];
struct Segment_Node{
ll lazy;
ll sum;
bool flag;
}seg[Maxn<<2|5];
std::vector<std::pair<ll,ll> > ans;
void push_up(int root){
seg[root].flag=seg[root<<1].flag&&seg[root<<1|1].flag;
if(seg[root].flag){
if(seg[root<<1].lazy==seg[root<<1|1].lazy){
seg[root].lazy=seg[root<<1].lazy;
}
else{
seg[root].flag=0;
}
}
}
void build(int root=1,int left=1,int right=n){
if(left==right){
seg[root].lazy=a[left];
seg[root].sum=b[left];
seg[root].flag=1;
return;
}
int mid=(left+right)>>1;
build(root<<1,left,mid),build(root<<1|1,mid+1,right);
seg[root].sum=seg[root<<1].sum+seg[root<<1|1].sum;
push_up(root);
}
void push_down(int root){
if(seg[root].flag){
seg[root<<1].lazy=seg[root].lazy,seg[root<<1|1].lazy=seg[root].lazy;
seg[root<<1].flag=seg[root<<1|1].flag=1;
seg[root].lazy=0,seg[root].flag=0;
}
else{
seg[root<<1].lazy+=seg[root].lazy,seg[root<<1|1].lazy+=seg[root].lazy;
seg[root].lazy=0;
}
}
void modify(int l,int r,int a,int root=1,int left=1,int right=n){
if(l>right||r<left){
return;
}
if(l<=left&&r>=right){
seg[root].lazy+=a;
return;
}
push_down(root);
int mid=(left+right)>>1;
modify(l,r,a,root<<1,left,mid),modify(l,r,a,root<<1|1,mid+1,right);
push_up(root);
}
void query(int l,int r,int root=1,int left=1,int right=n){
if(l>right||r<left){
return;
}
if(l<=left&&r>=right&&seg[root].flag){
ans.push_back(std::make_pair(seg[root].lazy,seg[root].sum));
return;
}
push_down(root);
int mid=(left+right)>>1;
query(l,r,root<<1,left,mid),query(l,r,root<<1|1,mid+1,right);
push_up(root);
}
void update(int l,int r,ll v,int root=1,int left=1,int right=n){
if(l>right||r<left){
return;
}
if(l<=left&&r>=right){
seg[root].flag=1,seg[root].lazy=v;
return;
}
push_down(root);
int mid=(left+right)>>1;
update(l,r,v,root<<1,left,mid),update(l,r,v,root<<1|1,mid+1,right);
push_up(root);
}
int main(){
read(n),read(q);
for(int i=1;i<=n;i++){
read(a[i]);
}
for(int i=1;i<=n;i++){
read(b[i]);
}
build();
for(int i=1;i<=q;i++){
int op;
read(op);
if(op==1){
int l,r,x;
read(l),read(r),read(x);
modify(l,r,x);
}
else{
int l,r;
read(l),read(r);
ans.clear();
query(l,r);
std::sort(ans.begin(),ans.end());
ll sum_all=0;
for(std::pair<ll,ll> i:ans){
sum_all+=i.second;
}
ll cur_sum=0;
ll ans_val=0;
for(std::pair<ll,ll> i:ans){
cur_sum+=i.second;
if(cur_sum>=sum_all/2){
ans_val=i.first;
break;
}
}
printf("%lld\n",ans_val);
update(l,r,ans_val);
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 344ms
memory: 21100kb
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 2624635344 2624635344 2057468653 2624635344 2933052096 2624635344 1816209814 3137610206 3137610206 3932599481 3932599481 3932599481 3932599481 3932599481 3932599481 3932599481 3137610206 4184571657 4184571657 4184571657 8352701848 7733092490 7733092490 77330...
result:
wrong answer 5th lines differ - expected: '874061694', found: '2624635344'