Submission #35522647


Source Code Expand

#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
#define per(i,a,n) for (ll i=n;i-->(ll)a;)

#define SEG_ROOT 1,0,n-1
#define SEG_L (o<<1)
#define SEG_R (o<<1|1)
#define mid (l+r)/2
#define SEG_L_CHILD SEG_L,l,mid
#define SEG_R_CHILD SEG_R,mid+1,r

ll read(){ll r;scanf("%lld",&r);return r;}

// Ex
using A3=std::array<ll,3>;
A3 seg[2'000'010]; // {sum, same?, value(只在same==true时才有意义)}

ll a[500'010];

void down(int o,int l,int r){
  assert(l!=r);
  if(seg[o][1]){
    ll v=seg[o][2];
    seg[SEG_L]={(mid-l+1)*v,true,v};
    seg[SEG_R]={(r-mid)*v,true,v};
  }
}

A3 up(int o){
  auto [s0,b0,v0]=seg[SEG_L];
  auto [s1,b1,v1]=seg[SEG_R];
  return seg[o]={s0+s1,b0&&b1&&v0==v1,v0};
}


A3 build(int o,int l,int r){
  if(l==r)return seg[o]={a[l],true,a[l]};
  build(SEG_L_CHILD);
  build(SEG_R_CHILD);
  return up(o);
}

A3 div(int o,int l,int r,int ql,int qr,ll x){
  if(ql<=l&&r<=qr&&seg[o][1]){
    seg[o][2]/=x;
    seg[o][0]=(r-l+1)*seg[o][2];
    return seg[o];
  }
  down(o,l,r);
  if(ql<=mid) div(SEG_L_CHILD,ql,qr,x);
  if(qr> mid) div(SEG_R_CHILD,ql,qr,x);
  return up(o);
}

A3 set(int o,int l,int r,int ql,int qr,ll x){
  if(ql<=l&&r<=qr) return seg[o]={x*(r-l+1),true,x};
  down(o,l,r);
  if(ql<=mid) set(SEG_L_CHILD,ql,qr,x);
  if(qr> mid) set(SEG_R_CHILD,ql,qr,x);
  return up(o);
}

ll sum(int o,int l,int r,int ql,int qr){
  if(ql<=l&&r<=qr)return seg[o][0];
  down(o,l,r);
  ll ret=0;
  if(ql<=mid)ret+=sum(SEG_L_CHILD,ql,qr);
  if(qr> mid)ret+=sum(SEG_R_CHILD,ql,qr);
  return ret;
}

int main(){
  int n=read();
  int q=read();
  rep(i,0,n)a[i]=read();
  build(SEG_ROOT);
  while(q--){
    int op=read();
    int l=read()-1;
    int r=read()-1;
    if(op==1){
      div(SEG_ROOT,l,r,read());
    }else if(op==2){
      set(SEG_ROOT,l,r,read());
    }else{
      printf("%lld\n",sum(SEG_ROOT,l,r));
    }
  }
  return 0;
}

Submission Info

Submission Time
Task Ex - I like Query Problem
User cromarmot
Language C++ (GCC 9.2.1)
Score 600
Code Size 1899 Byte
Status AC
Exec Time 425 ms
Memory 32256 KiB

Compile Error

./Main.cpp: In function ‘ll read()’:
./Main.cpp:13:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   13 | ll read(){ll r;scanf("%lld",&r);return r;}
      |                ~~~~~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 03_width_max_00.txt, 03_width_max_01.txt, 03_width_max_02.txt, 03_width_max_03.txt, 03_width_max_04.txt, 03_width_max_05.txt, 03_width_max_06.txt, 03_width_max_07.txt, 04_x_small_00.txt, 04_x_small_01.txt, 04_x_small_02.txt, 05_overflow_00.txt, 06_potential_00.txt, 06_potential_01.txt, 06_potential_02.txt, 06_potential_03.txt, 06_potential_04.txt, 06_potential_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 7 ms 3584 KiB
00_sample_01.txt AC 2 ms 3660 KiB
01_n_small_00.txt AC 62 ms 3644 KiB
01_n_small_01.txt AC 62 ms 3588 KiB
01_n_small_02.txt AC 63 ms 3592 KiB
01_n_small_03.txt AC 65 ms 3640 KiB
01_n_small_04.txt AC 65 ms 3712 KiB
02_random_00.txt AC 184 ms 18040 KiB
02_random_01.txt AC 175 ms 17864 KiB
02_random_02.txt AC 185 ms 17996 KiB
02_random_03.txt AC 229 ms 32136 KiB
02_random_04.txt AC 217 ms 32252 KiB
03_width_max_00.txt AC 187 ms 32068 KiB
03_width_max_01.txt AC 99 ms 31928 KiB
03_width_max_02.txt AC 101 ms 32132 KiB
03_width_max_03.txt AC 267 ms 31968 KiB
03_width_max_04.txt AC 165 ms 32184 KiB
03_width_max_05.txt AC 125 ms 32256 KiB
03_width_max_06.txt AC 178 ms 32256 KiB
03_width_max_07.txt AC 181 ms 32152 KiB
04_x_small_00.txt AC 255 ms 32144 KiB
04_x_small_01.txt AC 260 ms 32148 KiB
04_x_small_02.txt AC 250 ms 32164 KiB
05_overflow_00.txt AC 75 ms 32044 KiB
06_potential_00.txt AC 376 ms 32060 KiB
06_potential_01.txt AC 379 ms 32112 KiB
06_potential_02.txt AC 422 ms 31932 KiB
06_potential_03.txt AC 425 ms 31936 KiB
06_potential_04.txt AC 401 ms 32196 KiB
06_potential_05.txt AC 401 ms 32200 KiB