結果

問題 No.1802 Range Score Query for Bracket Sequence
ユーザー 蜜蜂蜜蜂
提出日時 2022-01-07 22:08:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,794 bytes
コンパイル時間 3,900 ms
コンパイル使用メモリ 228,828 KB
実行使用メモリ 7,048 KB
最終ジャッジ日時 2023-09-12 14:11:54
合計ジャッジ時間 8,971 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 227 ms
7,048 KB
testcase_02 AC 221 ms
6,924 KB
testcase_03 AC 221 ms
6,996 KB
testcase_04 AC 222 ms
6,924 KB
testcase_05 AC 221 ms
6,880 KB
testcase_06 AC 220 ms
6,892 KB
testcase_07 AC 223 ms
6,896 KB
testcase_08 AC 224 ms
6,860 KB
testcase_09 AC 217 ms
6,900 KB
testcase_10 AC 218 ms
6,920 KB
testcase_11 AC 205 ms
6,888 KB
testcase_12 AC 204 ms
6,888 KB
testcase_13 AC 209 ms
6,860 KB
testcase_14 AC 331 ms
6,928 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

int op(int a,int b){
  return a+b;
}
int e(){
  return 0;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n,q;
  cin>>n>>q;

  string s;
  cin>>s;

  vi a(n);
  rep(i,0,n){
    if(s[i]=='('){
      a[i]=0;
    }
    else{
      a[i]=1;
    }
  }

  vi sc(n-1);
  rep(i,0,n-1){
    if(a[i]==1&&a[i+1]==0){
      sc[i]=1;
    }
    else{
      sc[i]=0;
    }
  }

  segtree<int,op,e> seg(sc);

  while(q--){
    int x;
    cin>>x;

    if(x==1){
      int id;
      cin>>id;
      id--;

      a[id]=1-a[id];

      if(id<n-1){
        if(a[id]==1&&a[id+1]==0){
          seg.set(id,1);
        }
        else{
          seg.set(id,0);
        }
      }
      if(0<id){
        if(a[id-1]==1&&a[id]==0){
          seg.set(id-1,1);
        }
        else{
          seg.set(id-1,0);
        }
      }
    }
    else{
      int l,r;
      cin>>l>>r;
      l--;r--;

      int p=seg.prod(l,r);
      p++;
      if(a[l]==1){
        p--;
      }
      if(a[r]==0){
        p--;
      }
      cout<<p<<endl;
    }
  }
}
0