Submission #7509710


Source Code Expand

#include<bits/stdc++.h>

using namespace std;

long long n,a,b,_a[1000010],t[1000010],lz[1000010];

long long l(long long id){return id*2;}
long long r(long long id){return id*2+1;}

void push_up(long long id){
    t[id]=t[l(id)]+t[r(id)];
}

void build(long long id,long long ll,long long rr){
    lz[id]=0;

    if(ll==rr){t[id]=_a[ll];return ;}

    long long mid=(ll+rr)/2;
    build(l(id),ll,mid);
    build(r(id),mid+1,rr);

    push_up(id);
    //cout<<id<<endl;
}

void f(long long id,long long ll,long long rr,long long tg){
    lz[id]+=tg;
    t[id]+=tg*(rr-ll+1);
}

void push_down(long long id,long long ll,long long rr){
    long long mid=(ll+rr)/2;
    f(l(id),ll,mid,lz[id]);
    f(r(id),mid+1,rr,lz[id]);
    lz[id]=0;
}

void update(long long nl,long long nr,long long ll,long long rr,long long id,long long k){

    if(nl<=ll&&rr<=nr){
        t[id]+=k*(rr-ll+1);
        lz[id]+=k;

        return;
    }
    push_down(id,ll,rr);
    long long mid=(ll+rr)/2;
    if(nl<=mid) update(nl,nr,ll,mid,l(id),k);
    if(nr>mid) update(nl,nr,mid+1,rr,r(id),k);
    push_up(id);
    //cout<<"YJP AK IOI!";
}

long long q(long long nl,long long nr,long long ll,long long rr,long long id){
    long long ret=0;
    if(nl<=ll&&rr<=nr){return t[id];}
    long long mid=(ll+rr)/2;
    push_down(id,ll,rr);
    if(nl<=mid) ret+=q(nl,nr,ll,mid,l(id));
    if(nr>mid) ret+=q(nl,nr,mid+1,rr,r(id));
    return ret;
}

int main(){
    n=2;
    
    scanf("%lld %lld",&a,&b);
    build(1,1,n);
    
    update(1,1,1,n,1,a);
    update(2,2,1,n,1,-b);
    
    printf("%lld\n",q(1,2,1,n,1));
}

Submission Info

Submission Time
Task A - 積雪深差
User luogu_bot4
Language C++ (GCC 5.4.1)
Score 100
Code Size 1589 Byte
Status AC
Exec Time 2 ms
Memory 2304 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:68:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld",&a,&b);
                             ^

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 20
Set Name Test Cases
all 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 2 ms 2304 KB
00_sample_02.txt AC 2 ms 2304 KB
00_sample_03.txt AC 2 ms 2304 KB
test_01.txt AC 2 ms 2304 KB
test_02.txt AC 2 ms 2304 KB
test_03.txt AC 2 ms 2304 KB
test_04.txt AC 2 ms 2304 KB
test_05.txt AC 2 ms 2304 KB
test_06.txt AC 2 ms 2304 KB
test_07.txt AC 2 ms 2304 KB
test_08.txt AC 2 ms 2304 KB
test_09.txt AC 2 ms 2304 KB
test_10.txt AC 2 ms 2304 KB
test_11.txt AC 2 ms 2304 KB
test_12.txt AC 2 ms 2304 KB
test_13.txt AC 2 ms 2304 KB
test_14.txt AC 2 ms 2304 KB
test_15.txt AC 2 ms 2304 KB
test_16.txt AC 2 ms 2304 KB
test_17.txt AC 2 ms 2304 KB