結果

問題 No.876 Range Compress Query
ユーザー mint6421mint6421
提出日時 2019-12-11 17:25:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,861 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 169,200 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-06 13:06:56
合計ジャッジ時間 5,798 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


template< typename T >
struct BIT {
  vector< T > data;

  BIT(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret=Madd(ret,data[k]);
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k]=Madd(data[k],x);
  }
};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,q;
  cin>>n>>q;
  BIT<int> sum(2*n),num(2*n);
  rep(i,n){
    int x;
    cin>>x;
    sum.add(i,x);
    sum.add(i+1,-x);
  }

  rep(i,n-1){
    if(sum.sum(i)!=sum.sum(i+1)) num.add(i,1);
  }

  while(q--){
    int t,l,r;
    cin>>t>>l>>r;
    l--;r--;
    if(t==1){
      int x;
      cin>>x;
      if(sum.sum(l-1)!=sum.sum(l)) num.add(l-1,-1);
      if(sum.sum(r)!=sum.sum(r+1)) num.add(r,-1);
      sum.add(l,x);
      sum.add(r+1,-x);
      if(sum.sum(l-1)!=sum.sum(l)) num.add(l-1,1);
      if(sum.sum(r)!=sum.sum(r+1)) num.add(r,1);
    }else{
      cout<<1+num.sum(r-1)-num.sum(l-1)<<endl;
    }
  }

}
0