結果
問題 |
No.2901 Logical Sum of Substring
|
ユーザー |
![]() |
提出日時 | 2024-09-20 23:19:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,829 bytes |
コンパイル時間 | 4,368 ms |
コンパイル使用メモリ | 261,156 KB |
最終ジャッジ日時 | 2025-02-24 10:43:08 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | WA * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } ll op(ll a, ll b){ return min(a, b); } ll e(){ return 1e18; } ll mapping(ll f, ll x){ return f + x; } ll composition(ll g, ll f){ return g + f; } ll id(){ return 0; } int op2(int a, int b){ return a | b; } int e2(){ return 0; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n); rep(i,0,n){ cin >> a[i]; } vector<ll> init(n+1); vector<lazy_segtree<ll,op,e,ll,mapping,composition,id>> seg(k); rep(i,0,k){ seg[i] = lazy_segtree<ll,op,e,ll,mapping,composition,id>(n+1); } segtree<int,op2,e2> segor(a); int tmp; auto f = [&](int x) { return ((x >> tmp) & 1) == 0; }; rep(i,0,k){ rep(j,0,n+1){ tmp = i; int y = segor.max_right(j,f); seg[i].set(j, y-j); } } int q; cin >> q; while(q--){ int t; cin >> t; if (t == 1){ int i; cin >> i; i--; int v; cin >> v; int w = a[i]; a[i] = v; segor.set(i,0); rep(j,0,k){ if (((w>>j)&1) == ((v>>j)&1)) { continue; }else if((v>>j)&1){ tmp=j; int y = segor.min_left(i,f); int d = seg[j].get(i); seg[j].apply(y,i+1,-d); assert(seg[j].get(i) == 0); }else if((w>>j&1)){ tmp=j; int y = segor.min_left(i,f); int z = segor.max_right(i,f); int d = seg[j].get(i); seg[j].apply(y,i+1,z-i-d); assert(seg[j].get(i+1) + 1 == seg[j].get(i)); } } segor.set(i,v); }else{ int l, r; cin >> l >> r; l--; if (segor.prod(l, r) != (1<<k)-1){ cout << -1 << '\n'; continue; } int ub = r-l; int lb = 0; while (ub - lb > 1) { int t = (ub + lb) / 2; bool mode = 1; rep(i,0,k){ if (seg[i].prod(l, r-t) > t-1) { mode = 0; } } if (mode) ub = t; else lb = t; } cout << ub << '\n'; } } }