QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600871#6435. Paimon Segment TreemyloveATRIWA 7ms26880kbC++204.2kb2024-09-29 19:43:262024-09-29 19:43:29

Judging History

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

  • [2024-09-29 19:43:29]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:26880kb
  • [2024-09-29 19:43:26]
  • 提交

answer

#include<bits/stdc++.h>
#include<queue>
#include<string.h>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
//#define int long long
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nl t[n].l
#define nr t[n].r
#define gcd __gcd
#define itn int
using namespace std;
const int maxn=1e5+50;
const int N=1e5+50;
const int inf=1e18;
const int INF=2e18;
const int mod=1e9+7;
const double eps=1e-12;
#define pop_count __builtin_popcountll
//const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
struct Matrix
{
    int a[5][5];
    Matrix()
    {
        memset(a,0,sizeof(a));
    }

    Matrix operator*(const Matrix &b) const
    {
        Matrix res;
        for(int i=1; i<=4; i++)
            for(int j=1; j<=4; j++)
                for(int k=1; k<=4; k++)
                {
                    res.a[i][j]=(res.a[i][j]+a[i][k]*b.a[k][j]%mod)%mod;
                }
        return res;
    }
};
struct node{
    int l,r;
    Matrix b,laz;
}t[maxn];
int a[maxn];
struct Q{
    int id,l,r,typ,val;
    friend bool operator<(Q a,Q b){return a.val<b.val;}
}qy[maxn];
Matrix cg(int v)
{
    Matrix res;
    res.a[1][1]=res.a[2][2]=res.a[3][3]=res.a[3][4]=res.a[4][4]=1;
    res.a[1][2]=v;
    res.a[1][3]=res.a[1][4]=(ll)v*v%mod;
    res.a[2][3]=res.a[2][4]=2ll*v%mod;
    return res;
}

void merge(int n)
{
    rep(i,1,4)
    {
        rep(j,1,4)
        {
            t[n].b.a[i][j]=((ll)t[n<<1].b.a[i][j]+t[n<<1|1].b.a[i][j])%mod;
        }
    }
}
void push_down(int n)
{
    t[n<<1].b=t[n<<1].b*t[n].laz;
    t[n<<1|1].b=t[n<<1|1].b*t[n].laz;
    t[n<<1].laz=t[n<<1].laz*t[n].laz;
    t[n<<1|1].laz=t[n<<1|1].laz*t[n].laz;
    rep(i,1,4)
    {
        rep(j,1,4)
        if(i!=j) t[n].laz.a[i][j]=0;
        else
        t[n].laz.a[i][i]=1;
    }
}
void update(int n,int l,int r,int v)
{
    if(l>r) return;
    if(nl>=l&&nr<=r)
    {
        Matrix x=cg(v);
        t[n].b=t[n].b*x;
        t[n].laz=t[n].laz*x;
        return;
    }
    push_down(n);
    int mid=nl+nr>>1;
    if(l<=mid) update(n<<1,l,r,v);
    if(r>mid) update(n<<1|1,l,r,v);
    merge(n);
}
int query(int n,int l,int r)
{
    if(nl>=l&&nr<=r) return t[n].b.a[1][4];
    int mid=nl+nr>>1;
    push_down(n);
    int res=0;
    if(l<=mid) res+=query(n<<1,l,r);
    if(r>mid) res+=query(n<<1|1,l,r);
    return res;
}
void build(int n,int l,int r)
{
    nl=l,nr=r;
    rep(i,1,4) t[n].laz.a[i][i]=1;
    if(l==r)
    {
       t[n].b.a[1][1]=r-l+1;
       t[n].b.a[1][2]=a[l];
       t[n].b.a[1][3]=t[n].b.a[1][4]=(ll)a[l]*a[l]%mod;
       return;
    }
    int mid=nl+nr>>1;
    build(n<<1,l,mid);
    build(n<<1|1,mid+1,r);
    merge(n);
}
int l[maxn],r[maxn],x[maxn];
int ans[maxn];
void solve()
{
    int n,m,q;
    cin>>n>>m>>q;
    rep(i,1,n) cin>>a[i];
    build(1,1,n);
    rep(i,1,m)
    {
        cin>>l[i]>>r[i]>>x[i];
    }
    int cnt=0;
    rep(i,1,q)
    {
        int u,v,x,y;
        cin>>u>>v>>x>>y;
        qy[++cnt].l=u;
        qy[cnt].r=v;
        qy[cnt].val=x-1;
        qy[cnt].typ=-1;
        qy[cnt].id=i;
        qy[++cnt].l=u;
        qy[cnt].r=v;
        qy[cnt].val=y;
        qy[cnt].typ=1;
        qy[cnt].id=i;
    }
    sort(qy+1,qy+1+2*q);
    int now=1;
    rep(i,0,m)
    {
        if(i)
        {
            update(1,l[i],r[i],x[i]);
            update(1,1,l[i]-1,0);
            update(1,r[i]+1,n,0);
           // cout<<n<<'\n';
        }
       // cout<<query(1,4,4)<<'\n';
        while(now<=2*q&&qy[now].val<i)
        {
            now++;
        }
        while(now<=2*q&&qy[now].val==i)
        {
            ans[qy[now].id]=((ll)ans[qy[now].id]+qy[now].typ*query(1,qy[now].l,qy[now].r))%mod;
            // cout<<query(1,qy[now].l,qy[now].r);
            now++;
        }

    }
    rep(i,1,q) cout<<(ans[i]%mod+mod)%mod<<'\n';
    /*cout<<query(1,1,1);
    update(1,2,4,0);
    update(1,4,4,0);
   // update(1,4,4,0);
    cout<<query(1,4,4);*/
}


signed main()
{
   ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int __=1;
   //srand((time(0)));

  //cin>>__;

  while(__--)
  {
       solve();
  }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 26208kb

input:

3 1 1
8 1 6
2 3 2
2 2 0 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 26880kb

input:

4 3 3
2 3 2 2
1 1 6
1 3 3
1 3 6
2 2 2 3
1 4 1 3
4 4 2 3

output:

180
825
8

result:

ok 3 number(s): "180 825 8"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 26036kb

input:

100 107 180
-280960553 266308104 -997644864 856103777 592874377 674379235 -946339772 641750362 642418716 -360811715 -555543246 206614021 358239245 349842656 983198973 807518446 -66612455 -980932737 109826132 -109676067 51226145 452115561 -42729559 -950621304 -87009773 714026474 375317493 693260053 -...

output:

537106601
148797450
354994392
95238898
887178842
310817944
57896203
503824500
394253185
82155046
82741472
109582305
725986800
890089739
104121854
697971219
663690323
446536376
315264417
320500376
942692165
765343609
97198577
245336676
426632230
202861432
782352691
532229734
686045127
1608225
3202752...

result:

wrong answer 1st numbers differ - expected: '400489222', found: '537106601'