結果
問題 |
No.2992 Range ABCD String Query
|
ユーザー |
|
提出日時 | 2025-01-23 18:32:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,298 ms / 6,000 ms |
コード長 | 7,529 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 159,692 KB |
実行使用メモリ | 210,556 KB |
最終ジャッジ日時 | 2025-01-23 18:33:32 |
合計ジャッジ時間 | 62,959 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:242:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 242 | freopen(task".inp","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:243:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 243 | freopen(task".out","w",stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:247:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 247 | freopen(task1".inp","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:248:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 248 | freopen(task1".out","w",stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx2,tune=native") #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <locale> #include <map> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <unordered_set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <valarray> #include <vector> #include <cstring> #include <unordered_map> #include <cmath> #include <array> #include <cassert> #include <random> #include <chrono> using namespace std; #define BIT(i,j) (((i)>>(j))&1LL) #define MASK(i) (1LL<<(i)) #define ALL(x) (x).begin(),(x).end() #define SZ(x) (int)(x).size() #define fi first #define se second #define ull ungsigned long long #define ll long long #define ld long double #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define REPDIS(i,be,en,j) for(int i = (be); i<=(en); i+=j) #define REPD(i,be,en) for(int i = (be); i>=(en); i--) #define REP(i,be,en) for(int i = (be); i<=(en); i++) #define endl "\n" #define MP make_pair // #define int ll //-----------------------------------------------------------------------------------------------// inline void scan(){} template<typename F, typename... R> inline void scan(F &f,R&... r){cin>>f;scan(r...);} inline void print(){} template<typename F, typename... R> inline void print(F f,R... r){cout<<f;print(r...);} //-----------------------------------------------------------------------------------------------// void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif //------------------------------------------------------------------------------------------------// const ll LINF = 1e18; const int INF = 1e9; const int LOG = 20; const int MAXN = 2e5+7; const int N = 1e2+3; const int MOD = 1e9+7; const int BASE = 1e5; const ld EPS = 1e-9; const ld PI = acos(-1); const int OFFSET = 1e3; //------------------------------------------------------------------------------------------------// template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;} template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;} template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; } template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; } //------------------------------------------------------------------------------------------------// /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- */ int a[MAXN]; struct node { vvi f; node() { f.assign(4,vi(4,INF)); } node operator + (const node& other) { node res; for (int i = 0; i<4; i++) { for (int j = i; j<4; j++) { for (int k = i; k<=j; k++) { mini(res.f[i][j],f[i][k]+other.f[k][j]); } } } return res; } }; node tam; struct segment_tree { vector<node> st; int n; void build(int id, int l, int r) { if (l==r) { for (int i = 0; i<4; i++) { for (int j = i; j<4; j++) { int val = (a[l]<i || a[l]>j)?1:0; st[id].f[i][j] = val; } } return ; } int mid = (l+r)>>1; build(id<<1,l,mid); build(id<<1|1,mid+1,r); st[id] = st[id<<1]+st[id<<1|1]; } void update(int id, int l, int r, int pos, int c) { if (l>pos || r<pos) return ; if (l==r) { for (int i = 0; i<4; i++) { for (int j = i; j<4; j++) { int val = (c<i || c>j); st[id].f[i][j] = val; } } return ; } int mid = (l+r)>>1; update(id<<1,l,mid,pos,c); update(id<<1|1,mid+1,r,pos,c); st[id] = st[id<<1]+st[id<<1|1]; } node get(int id, int l, int r, int lo, int hi) { if (l>=lo && r<=hi) return st[id]; int mid = (l+r)>>1; if(hi<=mid){ return get(id<<1,l,mid,lo,hi); }else{ if(lo>mid){ return get(id<<1|1,mid+1,r,lo,hi); }else{ node p1 = get(id<<1,l,mid,lo,min(mid,hi)); node p2 = get(id<<1|1,mid+1,r,max(mid+1,lo),hi); return p1+p2; } } // cerr << l << " " << r << " " << lo << " " << hi << endl; // cerr << "WA" << endl; return tam; } void update(int pos, int c) { update(1,1,n,pos,c); } node get(int l, int r) { return get(1,1,n,l,r); } segment_tree(int _n):n(_n){ st.assign(4*n,node()); } }; int tran(char ch) { return ch-'A'; } void solve() { int n,q; cin >> n >> q; string s; cin >> s; for (int i = 0; i<n; i++) a[i+1] = tran(s[i]); segment_tree seg(n); seg.build(1,1,n); while (q--) { int op; cin >> op; if (op==1) { int x; cin >> x; char c; cin >> c; a[x] = tran(c); seg.update(x,tran(c)); }else { int l,r; cin >> l >> r; cout << seg.get(l,r).f[0][3] << endl; } } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } #define task1 "nothing" if(fopen(task1".inp","r")){ freopen(task1".inp","r",stdin); freopen(task1".out","w",stdout); } int test = 1; while(test--){ solve(); } cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n"; return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/