QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600923#6435. Paimon Segment TreeSusie_RainWA 4ms47304kbC++206.9kb2024-09-29 19:59:142024-09-29 19:59:17

Judging History

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

  • [2024-09-29 19:59:17]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:47304kb
  • [2024-09-29 19:59:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#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

const int maxn=1e5+50;
using i64 = long long;
template<class T>
constexpr T power(T a, i64 b) {
    T res {1};
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

constexpr i64 mul(i64 a, i64 b, i64 p) {
    i64 res = a * b - i64(1.L * a * b / p) * p;
    res %= p;
    if (res < 0) {
        res += p;
    }
    return res;
}

template<i64 P>
struct MInt {
    i64 x;
    constexpr MInt() : x {0} {}
    constexpr MInt(i64 x) : x {norm(x % getMod())} {}

    static i64 Mod;
    constexpr static i64 getMod() {
        if (P > 0) {
            return P;
        } else {
            return Mod;
        }
    }
    constexpr static void setMod(i64 Mod_) {
        Mod = Mod_;
    }
    constexpr i64 norm(i64 x) const {
        if (x < 0) {
            x += getMod();
        }
        if (x >= getMod()) {
            x -= getMod();
        }
        return x;
    }
    constexpr i64 val() const {
        return x;
    }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MInt inv() const {
        return power(*this, getMod() - 2);
    }
    constexpr MInt &operator*=(MInt rhs) & {
        if (getMod() < (1ULL << 31)) {
            x = x * rhs.x % int(getMod());
        } else {
            x = mul(x, rhs.x, getMod());
        }
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) & {
        return *this *= rhs.inv();
    }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
        i64 v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(MInt lhs, MInt rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) {
        return lhs.val() != rhs.val();
    }
    friend constexpr bool operator<(MInt lhs, MInt rhs) {
        return lhs.val() < rhs.val();
    }
};

template<>
i64 MInt<0>::Mod = 1e9+7;

constexpr int P = 1e9+7;
using Z = MInt<P>;
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
{
    Z 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]);
                }
        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(Z 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]=v*v;
    res.a[2][3]=res.a[2][4]=2*v;
    return res;
}

void merge(int n)
{
    rep(i,1,4)
    {
        rep(j,1,4)
        {
            t[n].b.a[i][j]=(t[n<<1].b.a[i][j]+t[n<<1|1].b.a[i][j]);
        }
    }
}
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);
}
Z 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);
    Z 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]=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];
Z 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]+=qy[now].typ*query(1,qy[now].l,qy[now].r);
            // cout<<query(1,qy[now].l,qy[now].r);
            now++;
        }

    }
    rep(i,1,q) cout<<(ans[i])<<'\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: 0ms
memory: 47084kb

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: 4ms
memory: 47304kb

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: 4ms
memory: 46752kb

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:

312749951
994879539
433998721
251688870
270874023
804315923
204625124
177466079
53941110
365848926
854789623
151618853
196741027
834743828
9283877
242310549
663095289
629945175
618582374
978460586
996983780
747200608
856156085
490791777
438502830
318644000
233613317
776246835
943743936
202927263
455...

result:

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