Submission #68240941


Source Code Expand

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

const int mod = 998244353;

int add(int a,int b){
  return (a+b)%mod; 
}

int sub(int a,int b) {
  return (mod+a-b)%mod; 
}

int mul(int a,int b) {
  return a*b%mod; 
}

int power(int a,int b) {
  if (b==0)return 1; 
  int u = power(a, b>>1); 
  return mul(mul(u,u),(b&1)?a:1); 
}

int inv (int a) {
  return power(a,mod-2); 
}

int divide(int a,int b) {
  assert(b!=0);
  return mul(a,inv(b));
}


class SegTree {
  
  #define mid ((l+r)>>1)
  #define left (p<<1)
  #define right (left|1)
  #define toleft left,l,mid
  #define toright right,mid+1,r
  vector<int> t; 
  vector<int> lazy; 
  int n;
  public:
  SegTree(int n): n(n), t(4*n, 0), lazy(4*n,-1) {}
  
  void build(vector<int> a) {
    assert((int)a.size()<=n); 
    
    function<void(int,int,int)> b = [&](int p,int l,int r) {
      if(l==r) {
        t[p] = a[l]; 
        return; 
      }
      b(toleft); b(toright); 
      t[p] = mer(t[left], t[right]);
    };
    b(1,0,a.size()-1); 
  }
  
  void update(int p,int l,int r,int i,int j, int val) {
    push(p,l,r); 
    if(l>=i&&r<=j) {
      lazy[p] = val; 
      push(p,l,r); 
      return; 
    }
    if(l>j || r<i)return; 
    update(toleft, i,j,val);
    update(toright,i,j,val); 
    t[p] = mer(t[left], t[right]); 
  }
  
  int query(int p,int l,int r,int i,int j) {
    push(p,l,r); 
    if(l>=i&&r<=j)return t[p]; 
    if (l>j|| r<i)return 0; 
    return mer(query(toleft,i,j), query(toright,i,j)); 
  }
  
  int mer(int a,int b) {
    return add(a,b); 
  }
  
  void push(int p,int l, int r) {
    if(lazy[p] == -1) return; 
    t[p] = mul(r-l+1, lazy[p]); 
    if(l!=r) lazy[left]=lazy[right] = lazy[p]; 
    lazy[p] = -1; 
  }
  #undef toright
  #undef toleft
  #undef mid
  #undef right
  #undef left 
};
signed main() {
  int n; 
  cin>>n; 
  int m; 
  cin>>m; 
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i]; 
  
  SegTree seg(n); 
  seg.build(a); 
  
  for(int i=0;i<m;i++){
    int l,r; 
    cin>>l>>r; 
    l--; r--; 
    //cout<<l << " "<<r<<endl; 
    int sum = seg.query(1,0,n-1,l,r); 
    int invRl = inv(r-l+1); 
    int setV = mul(sum,invRl); 
    seg.update(1,0,n-1,l,r,setV); 
  }
  
  for(int i=0;i<n;i++){
    cout<<seg.query(1,0,n-1,i,i)<<" ";
  }
}

Submission Info

Submission Time
Task F - Random Gathering
User mafailure
Language C++ 20 (gcc 12.2)
Score 500
Code Size 2391 Byte
Status AC
Exec Time 412 ms
Memory 18884 KiB

Compile Error

Main.cpp: In constructor ‘SegTree::SegTree(long long int)’:
Main.cpp:44:7: warning: ‘SegTree::n’ will be initialized after [-Wreorder]
   44 |   int n;
      |       ^
Main.cpp:42:15: warning:   ‘std::vector<long long int> SegTree::t’ [-Wreorder]
   42 |   vector<int> t;
      |               ^
Main.cpp:46:3: warning:   when initialized here [-Wreorder]
   46 |   SegTree(int n): n(n), t(4*n, 0), lazy(4*n,-1) {}
      |   ^~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 49
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3472 KiB
00_sample_01.txt AC 1 ms 3544 KiB
00_sample_02.txt AC 1 ms 3600 KiB
01_random_03.txt AC 402 ms 18684 KiB
01_random_04.txt AC 405 ms 18800 KiB
01_random_05.txt AC 412 ms 18788 KiB
01_random_06.txt AC 410 ms 18640 KiB
01_random_07.txt AC 405 ms 18656 KiB
01_random_08.txt AC 406 ms 18736 KiB
01_random_09.txt AC 403 ms 18676 KiB
01_random_10.txt AC 407 ms 18740 KiB
01_random_11.txt AC 252 ms 9700 KiB
01_random_12.txt AC 287 ms 9948 KiB
01_random_13.txt AC 92 ms 8156 KiB
01_random_14.txt AC 179 ms 13672 KiB
01_random_15.txt AC 235 ms 16900 KiB
01_random_16.txt AC 406 ms 18792 KiB
01_random_17.txt AC 353 ms 18672 KiB
01_random_18.txt AC 324 ms 18720 KiB
01_random_19.txt AC 406 ms 18740 KiB
01_random_20.txt AC 352 ms 18692 KiB
01_random_21.txt AC 329 ms 18628 KiB
01_random_22.txt AC 409 ms 18672 KiB
01_random_23.txt AC 349 ms 18692 KiB
01_random_24.txt AC 327 ms 18664 KiB
01_random_25.txt AC 407 ms 18884 KiB
01_random_26.txt AC 352 ms 18740 KiB
01_random_27.txt AC 328 ms 18732 KiB
01_random_28.txt AC 263 ms 18752 KiB
01_random_29.txt AC 264 ms 18724 KiB
01_random_30.txt AC 403 ms 18648 KiB
01_random_31.txt AC 397 ms 18720 KiB
01_random_32.txt AC 396 ms 18736 KiB
01_random_33.txt AC 403 ms 18712 KiB
01_random_34.txt AC 396 ms 18800 KiB
01_random_35.txt AC 362 ms 18160 KiB
01_random_36.txt AC 224 ms 4540 KiB
01_random_37.txt AC 126 ms 10024 KiB
01_random_38.txt AC 1 ms 3540 KiB
01_random_39.txt AC 1 ms 3532 KiB
01_random_40.txt AC 69 ms 3516 KiB
01_random_41.txt AC 139 ms 3640 KiB
01_random_42.txt AC 150 ms 3528 KiB
01_random_43.txt AC 142 ms 3548 KiB
01_random_44.txt AC 191 ms 3704 KiB
01_random_45.txt AC 153 ms 3628 KiB
01_random_46.txt AC 176 ms 3640 KiB
01_random_47.txt AC 191 ms 3696 KiB
01_random_48.txt AC 120 ms 3536 KiB