結果

問題 No.3853 Unique Letters between Equal Letters
コンテスト
ユーザー ふらわぁ
提出日時 2026-12-05 00:42:37
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 4,652 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,807 ms
コンパイル使用メモリ 405,708 KB
実行使用メモリ 48,088 KB
最終ジャッジ日時 2026-12-05 00:42:52
合計ジャッジ時間 14,658 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//from https://yukicoder.me/users/24897/ai_code/29
//AI fix
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#ifdef _MSC_VER
#include <intrin.h>
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using P = pair<ll, ll>;
#define endl "\n"
#define rep1(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,a,b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define rep(...) OVERLOAD_REP(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define rrep(i,n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
constexpr int MINT_MOD = 998244353;
const ll mod = MINT_MOD;
const ll inf = 4000000000000000000ll;
const ld eps = ld(0.00000000001);
static const long double pi = 3.141592653589793;
constexpr ll MAX = 2000010;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class U>bool chmax(T &a,const U b) { if (a<b) { a=b; return 1; } return 0;}
template<class T,class U>bool chmin(T &a,const U b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<V<V<T>>>;
template <class T>
auto mvec(T val, ll n) { return V<T>(n, val); }
template <class T, class... Args>
auto mvec(T val, ll n, Args... args) {
    return V<decltype(mvec(val, args...))>(n, mvec(val, args...));
}
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / i);}}}sort(all(ans)); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=gcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}
void cincout(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout<< fixed << setprecision(15);
}

struct S{
  V<ll> l,r;
  ll ans;
};

bool can(V<ll> cen,ll l,ll r){
  bool ans=true;
  set<ll> a;
  rep(i,l+1,r){
    if(a.count(cen[i])) ans=false;
    else a.insert(cen[i]);
  }
  return ans;
}

S op(S a,S b){
  ll aans=0;
  V<ll> cen;
  rep(i,a.r.size()){
    cen.push_back(a.r[i]);
  }
  rep(i,b.l.size()){
    cen.push_back(b.l[i]);
  }
  ll le=0;
  rep(ri,cen.size()){
    rep(j,le,ri){
      if(cen[j]==cen[ri]){
        if(!can(cen,j,ri)) le=j+1;
      }
    }
    if(le>=a.r.size()) break;
    if(ri>=a.r.size()) aans+=max(0LL,min((ll)a.r.size()-1,(ll)ri-2)-le+1);
  }
  V<ll> ls=a.l,rs=a.r;
  ls.insert(ls.end(),all(b.l));
  rs.insert(rs.end(),all(b.r));
  if(ls.size()>30) ls.resize(30);
  if(rs.size()>30) rs.erase(rs.begin(),rs.end()-30);
  return S{ls,rs,a.ans+b.ans+aans};
}

S e(){
  V<ll> bl;
  return{bl,bl,0};
}

S leaf(ll x){
  auto a=mvec(x,1);
  return{a,a,0};
}

int main(){
  cincout();
  ll n,q; cin>>n>>q;
  string s; cin>>s;
  V<S> init(n);
  rep(i,n){
    ll x=s[i]-'0';
    init[i]=leaf(x);
  }
  segtree<S,op,e> seg(init);
  rep(i,q){
    ll a,b; cin>>a>>b;
    seg.set(a-1,leaf(b));
    cout<<seg.prod(0,n).ans<<endl;
  }
  return 0;
}
0