求助 ODT,WA on #4
查看原帖
求助 ODT,WA on #4
239192
淸梣ling楼主2022/8/17 20:52

在第 4 个点 WA 了,求大佬帮忙挑错!!

wrong answer 420th numbers differ - expected: '366377069', found: '363502405'

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
struct node
{
    int l,r;
    mutable ll val;
    node(int _l, int _r, ll _v) : l(_l),r(_r),val(_v) {};
    node() {}
    friend bool operator<(const node a, const node b)
    {
        return a.l<b.l;
    }
};

ll n,m,seed,vmax;
set<node> s;
node tmp[100100];
int cnt;

ll rnd()
{
    ll ans=seed;
    seed=(seed*7+13)%1000000007;
    return ans;
}
ll qpow(ll a, ll b, ll p)
{
    ll ans=1;
    for(; b; b>>=1,(a*=a)%=p)
    if(b&1) (ans*=a)%=p;
    return ans;
}
bool cmp(const node a, const node b)
{
    return a.val<b.val;
}
auto spilt(int x) -> set<node>::iterator
{
    if(x>n) return s.end();
    auto p = --s.upper_bound(node(x, 0, 0));
    if(p->l==x) return p;
    node a=*p,b=*p; a.r=x-1; b.l=x;
    s.erase(p);
    s.insert(a);
    return s.insert(b).first;
}
void assign(int l, int r, ll x)
{
    auto pr=spilt(r+1),pl=spilt(l);
    s.erase(pl, pr);
    s.insert(node(l, r, x));
}
void add(int l, int r, ll x)
{
    auto pr=spilt(r+1),pl=spilt(l);
    while(pl!=pr) pl->val+=x,++pl;
}
ll getkth(int l, int r, int k)
{
    auto pr=spilt(r+1),pl=spilt(l);
    cnt=0;
    while(pl!=pr) tmp[++cnt]=*pl,++pl;
    sort(tmp+1, tmp+1+cnt, cmp);
    for(int i=1; i<=cnt; i++)
    {
        if(tmp[i].r-tmp[i].l+1<k)
        k-=tmp[i].r-tmp[i].l+1;
        else
        return tmp[i].val;
    }
    return -1;
}
ll order4(int l, int r, ll x, ll p)
{
    ll ans=0;
    auto pr=spilt(r+1),pl=spilt(l);
    while(pl!=pr)
    ans=(ans+qpow(pl->val%p, x, p)*(pl->r-pl->l+1)%p)%p,++pl;
    return ans;
}
int main()
{
    int i;
    node a(1, 1, 0);

    cin>>n>>m>>seed>>vmax;
    for(i=1; i<=n; i++)
    {
        ll x=rnd()%vmax+1;
        if(a.val&&a.val!=x)
        {
            s.insert(a);
            a.l=a.r=i; a.val=x;
        }
        else
        ++a.r,a.val=x;
    }
    s.insert(a);

    for(i=1; i<=m; i++)
    {
        ll opt=rnd()%4+1,l=rnd()%n+1,r=rnd()%n+1,x,y;
        if(l>r) swap(l, r);
        if(opt==3) x=rnd()%(r-l+1)+1;
        else x=rnd()%vmax+1;
        if(opt==4) y=rnd()%vmax+1;

        switch (opt)
        {
        case 1:
            add(l, r, x);
            break;
        case 2:
            assign(l, r, x);
            break;
        case 3:
            printf("%lld\n", getkth(l, r, x));
            break;
        case 4:
            printf("%lld\n", order4(l, r, x, y));
            break;
        }
    }
    return 0;
}
```cpp
2022/8/17 20:52
加载中...