QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733791#8951. 澡堂zhulexuan0 242ms363064kbC++146.5kb2024-11-10 21:05:342024-11-10 21:05:42

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 21:05:42]
  • 评测
  • 测评结果:0
  • 用时:242ms
  • 内存:363064kb
  • [2024-11-10 21:05:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
    T w=1; n=0; char ch=getchar();
    while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
    while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
    n*=w;
}
template<typename T>inline void write(T x){
    if (x==0){ putchar('0'); return ; }
    T tmp;
    if (x>0) tmp=x;
    else tmp=-x;
    if (x<0) putchar('-');
    char F[105];
    long long cnt=0;
    while (tmp){
        F[++cnt]=tmp%10+48;
        tmp/=10;
    }
    while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 1000005;
ll n,m,q,ts;
ll a[N];//原本的值
ll val[N];//限制的权值
ll calc_sum(ll l,ll r){
    if (l>r) return 0;
    return (r-l)/m + 1;
}
ll calc_pos(ll l,ll r){//[l,r]内最后一个和l%m同余的位置
    if (l>r) return l;
    else return l + (r-l)/m * m;
}
ll Nxt(ll p,ll op){//p后面第一个同余op的位置
    ll o = p%m;
    if (o==op) return p;
    if (o<op) return p+op-o;
    if (o>op) return p+(op+m)-o;
}
struct ST{//查询从某个点x开始,到r,最优一个前缀最小值和总贡献数(原序列意义下的总贡献数)
    ll lg;
    struct infor{
        ll p,v;
        infor(ll _p=0,ll _v=0){
            p = _p, v = _v;
        }
    };
    ll a[N];
    infor f[21][N];
    void init(){
        ll i,j;
        //找右边第一个%m同余的比a_i小的位置
        ll top = 0, q[N];
        fr(i,0,m-1){//%m同余
            top = 0;
            rfr(j,n,1){
                if (j%m!=i) continue;
                // printf("i = %lld , j = %lld\n",i,j);
                while (top>0 && a[j]<=a[q[top]]) top--;
                if (top==0) f[0][j] = infor( n+1 , a[j] * calc_sum(j,n) );
                else f[0][j] = infor( q[top] , a[j] * calc_sum(j,q[top]-1) );
                q[++top] = j;
            }
        }
        // fr(i,1,n) printf("f[0][%lld] : p = %lld , val = %lld\n",i,f[0][i].p,f[0][i].v);
        for (i=1; (1<<i)<=n; lg = i, i++)
            fr(j,1,n){
                ll x = f[i-1][j].p;
                if (x<=n){
                    f[i][j].p = f[i-1][x].p;
                    f[i][j].v = f[i-1][j].v + f[i-1][x].v;
                }
                else f[i][j] = f[i-1][j];
            }
    }
    pair<ll,ll> qry(ll x,ll r){//从x开始,以r为右端点
        // printf("\nqry %lld %lld\n",x,r);
        // make_pair( 区间内的贡献,最终的最小值 )
        ll i, ans = 0;
        rfr(i,lg,0){
            if (f[i][x].p<=r){
                ans += f[i][x].v;
                x = f[i][x].p;
            }
        }
        // printf("x = %lld\n",x);
        ans += a[x] * calc_sum(x,r);
        return make_pair(a[x],ans);
    }
    ll find(ll x,ll val){//从x开始第一个<val的位置
        if (a[x]<val) return x;
        for (ll i=lg; i>=0; i--){
            ll p = f[i][x].p;
            if (p<=n && a[p]>=val) x = p;
        }
        return f[0][x].p;
    }
}st;
pair<ll,ll> solve(ll l,ll r,ll pre,ll d){//意义见实现
    // printf("\n solve %lld ~ %lld , pre = %lld , delta = %lld\n",l,r,pre,d);
    if (l>r || l>n) return make_pair(pre,0);
    ll p = st.find(l,pre-d);
    // printf("p = %lld\n",p);
    if (p>r){
        // printf("return %lld %lld\n",pre,calc_sum(l,r)*pre);
        return make_pair(pre,calc_sum(l,r)*pre);
    }
    pair<ll,ll> v = st.qry(p,r);
    ll ans = calc_sum(l,p-1)*pre + (v.second+calc_sum(p,r)*d);
    // printf("return %lld %lld\n",v.first+d,ans);
    return make_pair(v.first+d,ans);
}
ll find_l(ll tms){//<=tms的最后一个位置
    ll l = 1, r = n, mid = (l+r)>>1;
    while (l<=r){
        mid = (l+r)>>1;
        if (a[mid]<=tms) l = mid+1;
        else r = mid-1;
    }
    return r;
}
pair<ll,ll> push(pair<ll,ll> p,ll v){
    Min(p.first,v); p.second += p.first;
    return p;
}
ll solve1(ll x,ll y,ll nwv){//向后放
    // printf("solve1 %lld --> %lld : nwv = %lld\n",x,y,nwv);
    ll i, ans = 0;
    fr(i,1,min(n,m)){//起点
        // printf("\n\n\n\n\n i = %lld\n",i);
        pair<ll,ll> v = solve(i,x-1,inf,0); ans += v.second;
        // printf("v1 : %lld %lld\n",v.first,v.second);
        ll p = Nxt(x,i%m);
        v = solve(Nxt(x,i%m)+1,y,v.first,-ts);// ans += v.second;
        // p = calc_pos(y,i%m);
        if (i%m==y%m) v = push(v,nwv);
        // printf("v2 : %lld %lld\n",v.first,v.second);
        ans += v.second;
        v = solve(Nxt(y+1,i%m),n,v.first,0); ans += v.second;
    }
    return ans;
}
ll solve2(ll x,ll nwv){//位置不变
    ll i, ans = 0;
    fr(i,1,min(n,m)){
        if (x%m!=i%m)//本来的值不用变
            ans += st.qry(i,n).second;
        else{
            pair<ll,ll> p;
            p = push( solve(i,x-1,inf,0) , nwv );
            ans += p.second + solve(x+m,n,p.first,0).second;
        }
    }
    return ans;
}
ll solve3(ll x,ll y,ll nwv){//向前放
    ll i, ans = 0;
    fr(i,1,min(n,m)){
        pair<ll,ll> v = solve(i,y-1,inf,0);
        // ll p = calc_pos(i,y);
        if (i%m==y%m) v = push(v,nwv);
        ans += v.second;
        v = solve(Nxt(y+1,i)-1,x-1,v.first,ts); ans += v.second;
        // p = calc_pos(p+m,x-1)+m;
        v = solve(Nxt(x+1,i),n,v.first,ts); ans += v.second;
    }
    return ans;
}
int main(){
	// freopen("a.in","r",stdin);
//	freopen(".out","w",stdout);
    ll i,j;
    read(n); read(m); read(q); read(ts);
    fr(i,1,n) read(a[i]), val[i] = i*ts - a[i];
    // printf("___\n");
    fr(i,1,n) st.a[i] = val[i]; st.init();//预处理
    // printf("___\n");
    ll all = 0; fr(i,1,n) all = all+i*ts-a[i];
    while (q--){
        ll x,y,t;
        read(x); read(t);
        ll p = find_l(t);
        if (p>=x) y = p; else y = p+1;
        // printf("x = %lld , y = %lld\n",x,y);
        ll ans = 0;
        if (x< y) ans = solve1(x,y,y*ts-t);
        if (x==y) ans = solve2(x,y*ts-t);
        if (x> y) ans = solve3(x,y,y*ts-t);
        // printf("del = %lld\n",ans);
        // printf("new all = %lld\n",all+a[x]-t);
        ans = (all+a[x]-t) - ans;
        write(ans); putchar('\n');
    }
    return 0;
}
//g++ submit.cpp -o submit -Wall -Wl,--stack=512000000 -std=c++11 -O2

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 339716kb

input:

1000 5 1000 1969617
59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...

output:

929380673761
929307941427
929311284605
929352504654
929355884427
929353924852
929312778826
929380506868
929387050194
929366041414
929340957640
929367389384
929309238860
929268645139
929394195489
929368744147
929333743956
929276443047
929292050360
929299939415
929422325762
929344900277
929378709810
9...

result:

wrong answer 1st lines differ - expected: '145473107761', found: '929380673761'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 219ms
memory: 363012kb

input:

1000000 1 100000 1165
83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...

output:

532526465396468
532526382684731
532526432384333
532526335149396
532526336776485
532526441656649
532526419074182
532526448368068
532526461593049
532526446718271
532526451561778
532526448430580
532526467785967
532526436580949
532526455448611
532526418610940
532526437620392
532526421767627
532526361938...

result:

wrong answer 1st lines differ - expected: '532526465394304', found: '532526465396468'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 242ms
memory: 363064kb

input:

1000000 5 100000 1887
112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...

output:

893581369200654
893581384430309
893581451301452
893581330800924
893581344976960
893581338934741
893581285838322
893581310952748
893581355256978
893581298292366
893581316484906
893581400307446
893581430546881
893581415054451
893581357284055
893581356779155
893581330455009
893581389776264
893581353154...

result:

wrong answer 1st lines differ - expected: '138785143191754', found: '893581369200654'

Subtask #6:

score: 0
Skipped

Dependency #3:

0%