QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1310#828287#9774. Same SumzhenghanyundxbtSuccess!2024-12-23 16:45:352024-12-23 17:01:43

Details

Extra Test:

Wrong Answer
time: 29ms
memory: 102020kb

input:

199180 1
63515 45692 56238 34555 85168 91971 17120 5741 71513 72137 29079 27271 19495 45720 54339 80446 5761 91044 55151 48044 14037 74659 78432 32872 56148 38632 12627 92593 94525 37029 30159 38287 10638 72343 29175 87844 61382 78083 26601 33934 3634 74955 51375 70036 42118 89859 5211 62812 51113 2...

output:

Yes

result:

wrong answer expected NO, found YES [1st token]

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#828287#9774. Same SumdxbtWA 1906ms111220kbC++146.9kb2024-12-23 15:31:572024-12-23 17:11:18

answer

/* by IceKylin */
/* -std=c++14 -O2 -static */

#include <bits/stdc++.h>
using namespace std;
#define F(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define G(i,l,r) for(int i=(l),i##end=(r);i>=i##end;--i)
#define pii pair<int,int>
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define ep emplace_back
using namespace std;
typedef long long ll;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

/* import */

namespace IceKylin {
#define ls (k << 1)
#define rs (k << 1 | 1)
constexpr int N = 2e5 + 5;
constexpr int B = 9;
constexpr ll p = static_cast<ll>(1e16) + 2137;
int n, q, a[N];
struct info {
  int d[B];
  __int128 pw1;
  info() {}
  info(ll v) {
    pw1 = v;
    for (int i = 0; i <= B - 1; ++i) d[i] = 0;
    d[v % B] = 1;
  }
  inline friend info operator+(const info &lhs, const info &rhs) {
    info k;
    k.pw1 = lhs.pw1 + rhs.pw1;
    for (int i = 0; i < B; ++i) k.d[i] = lhs.d[i] + rhs.d[i];
    return k;
  }
} t[N << 2];
ll tag[N << 2], len[N << 2];
void build(int k, int l, int r) {
  len[k] = r - l + 1;
  if (l == r) {
    t[k] = info(a[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(ls, l, mid), build(rs, mid + 1, r);
  t[k] = t[ls] + t[rs];
}
void upd(int k, __int128 v) {
  t[k].pw1 = t[k].pw1 + v * len[k];
  int nd[B];
  for (int i = 0; i < B; ++i) {
    nd[(i + v % B + B) % B] = t[k].d[i];
  }
  for (int i = 0; i < B; ++i) t[k].d[i] = nd[i];
  tag[k] += static_cast<ll>(v);
}
void pushdown(int k) {
  if (!tag[k]) return;
  upd(ls, tag[k]), upd(rs, tag[k]);
  tag[k] = 0;
}
void update(int k, int l, int r, int x, int y, __int128 v) {
  if (x <= l && r <= y) {
    upd(k, v);
    return;
  }
  pushdown(k);
  int mid = (l + r) >> 1;
  if (x <= mid) update(ls, l, mid, x, y, v);
  if (y > mid) update(rs, mid + 1, r, x, y, v);
  t[k] = t[ls] + t[rs];
}
info query(int k, int l, int r, int x, int y) {
  if (x <= l && r <= y) return t[k];
  pushdown(k);
  int mid = (l + r) >> 1;
  if (x <= mid && y > mid) return query(ls, l, mid, x, y) + query(rs, mid + 1, r, x, y);
  if (x <= mid) return query(ls, l, mid, x, y);
  return query(rs, mid + 1, r, x, y);
}
// void main() {
//   ios::sync_with_stdio(false);
//   cin >> n >> q;
//   for (int i = 1; i <= n; ++i) cin >> a[i];
//   build(1, 1, n);
//   while (q--) {
//     int op;
//     cin >> op;
//     if (op == 1) {
//       int l, r, x;
//       cin >> l >> r >> x;
//       update(1, 1, n, l, r, x);
//     } else {
//       int l, r;
//       cin >> l >> r;
//       info x = query(1, 1, n, l, r);
//       if (x.pw1 % ((r - l + 1) / 2)) {
//         cout << "No\n";
//         continue;
//       }
//       __int128 v = x.pw1 / ((r - l + 1) / 2);
//       update(1, 1, n, l, r, -v);
//       info y = query(1, 1, n, l, r);
//       bool flag = (x.d[0] == y.d[0]);
//       for (int i = 1; i < B; ++i) {
//         if (x.d[i] != y.d[B - i]) {
//           flag = false;
//           break;
//         }
//       }
//       cout << (flag ? "Yes\n" : "No\n");
//       update(1, 1, n, l, r, v);
//     }
//   }
// }
}
constexpr int mod=12331337;
struct node
{
  ll a,b,c,d,e,f,s,t;
  node(){a=b=c=d=e=0,f=1;}
  node(ll a1,ll b1,ll c1,ll d1,ll e1,ll f1,ll s1,ll t1)
  {
    s=s1,t=t1,a=a1,b=b1,c=c1,d=d1,e=e1,f=f1;
  }
  void add(ll x)
  {
    x%=mod;
    ll p1=x,p2=x*p1%mod,p3=p2*p1%mod,p4=p3*p1%mod,p5=p4*p1%mod,p6=p5*p1%mod,p7=p6*p1%mod;
    s=(s+7*t%mod*p1+21*a%mod*p2+35*b%mod*p3+35*c%mod*p4+21*d%mod*p5+7*e%mod*p6%mod+f*p7)%mod;
    t=(t+6*a%mod*p1+15*b%mod*p2+20*c%mod*p3+15*d%mod*p4+6*e%mod*p5+f*p6%mod)%mod;
    a=(a+5*b%mod*p1+10*c%mod*p2+10*d%mod*p3+5*e%mod*p4+f*p5)%mod;
    b=(b+4*c%mod*p1%mod+6*d%mod*p2+4*e%mod*p3+f*p4)%mod;
    c=(c+3*d%mod*p1%mod+3*e%mod*p2+f*p3)%mod;
    d=(d+2*e%mod*p1+f*p2)%mod;
    e=(e+f*p1)%mod;
  }
  node operator+(const node &A)const
  {
    return node{a+A.a,b+A.b,c+A.c,d+A.d,e+A.e,f+A.f,s+A.s,t+A.t};
  }
  void print()
  {
    cerr<<s<<' '<<t<<' '<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<'\n';
  }
}tr[200009<<2];
ll tag[200009<<2];
ll a[200009<<2];
ll qpow(ll x,ll y)
{
  ll res=1;
  for(;y;y>>=1,x=x*x%mod)if(y&1)res=res*x%mod;
  return res;
}
void pushdown(int o)
{
  if(tag[o])
  {
    tag[o<<1]+=tag[o];
    tag[o<<1|1]+=tag[o];
    tr[o<<1].add(tag[o]);
    tr[o<<1|1].add(tag[o]);
    tag[o]=0;
    return ;
  }
}
void add(int l,int r,int o,int a,int b,int c)
{
  if(a<=l && r<=b)return tr[o].add(c),tag[o]+=c,void();
  int mid=l+r>>1;
  pushdown(o);
  if(a<=mid)add(l,mid,o<<1,a,b,c);
  if(b>mid) add(mid+1,r,o<<1|1,a,b,c);
  tr[o]=tr[o<<1]+tr[o<<1|1];
}
ll ask(int l,int r,int o,int a,int b)
{
  if(a<=l && r<=b)return tr[o].e;
  int mid=l+r>>1;
  pushdown(o);
  if(b<=mid)return ask(l,mid,o<<1,a,b);
  if(a>mid) return ask(mid+1,r,o<<1|1,a,b);
  return (ask(l,mid,o<<1,a,b)+ask(mid+1,r,o<<1|1,a,b))%mod;
}
node ask1(int l,int r,int o,int a,int b)
{
  if(a<=l && r<=b)return tr[o];
  int mid=l+r>>1;
  pushdown(o);
  if(b<=mid)return ask1(l,mid,o<<1,a,b);
  if(a>mid) return ask1(mid+1,r,o<<1|1,a,b);
  return (ask1(l,mid,o<<1,a,b)+ask1(mid+1,r,o<<1|1,a,b));
}
void build(int l,int r,int o)
{
  if(l==r)return tr[o].add(a[l]),void();
  int mid=l+r>>1;
  build(l,mid,o<<1);
  build(mid+1,r,o<<1|1);
  tr[o]=tr[o<<1]+tr[o<<1|1];
}
signed main()
{
#ifndef ONLINE_JUDGE
  assert(freopen("test.in", "r", stdin));
  assert(freopen("test.out", "w", stdout));
#endif
  cin.tie(0)->sync_with_stdio(false);
  int n,q;
  cin>>n>>q;

  IceKylin::n = n;
  IceKylin::q = q;
  F(i,1,n)cin>>a[i], IceKylin::a[i] = a[i];
  IceKylin::build(1, 1, n);
  build(1,n,1);
  /*node s;
  s.print();
  s.add(1);
  s.print();
  s.add(1);
  s.print();*/
  int test=0;
  F(cc,1,q)
  {
    int op;
    cin>>op;
    if(op==1)
    {
      int l,r,c;
      cin>>l>>r>>c;
      add(1,n,1,l,r,c);
      IceKylin::update(1, 1, n, l, r, c);
    }
    else
    {
      test++;
      int l,r;
      cin>>l>>r;
      ll sum=ask(1,n,1,l,r)*qpow(r-l+1,mod-2)%mod;
    //  cerr<<"sum"<<sum<<'\n';
      add(1,n,1,l,r,mod-sum);
      node p=ask1(1,n,1,l,r);
    //  if(test==953)
    //  p.print();
      if(p.s%mod==0&&p.c%mod==0&&p.a%mod==0){
        IceKylin::info x = IceKylin::query(1, 1, n, l, r);
        if (x.pw1 % ((r - l + 1) / 2)) {
          puts("No");
        } else {
          __int128 v = x.pw1 / ((r - l + 1) / 2);
          IceKylin::update(1, 1, n, l, r, -v);
          IceKylin::info y = IceKylin::query(1, 1, n, l, r);
          bool flag = (x.d[0] == y.d[0]);
          for (int i = 1; i < IceKylin::B; ++i) {
            if (x.d[i] != y.d[IceKylin::B - i]) {
              flag = false;
              break;
            }
          }
          puts(flag ? "Yes" : "No");
          IceKylin::update(1, 1, n, l, r, v);
        }
      }
      else puts("No");
      add(1,n,1,l,r,sum);
    }
  }
  return 0;
}