結果

問題 No.2901 Logical Sum of Substring
ユーザー 👑 kmjpkmjp
提出日時 2024-09-21 12:01:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,123 ms / 3,000 ms
コード長 2,763 bytes
コンパイル時間 2,525 ms
コンパイル使用メモリ 213,844 KB
実行使用メモリ 167,424 KB
最終ジャッジ日時 2024-09-21 12:01:56
合計ジャッジ時間 30,742 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
134,272 KB
testcase_01 AC 76 ms
134,296 KB
testcase_02 AC 74 ms
134,160 KB
testcase_03 AC 73 ms
134,160 KB
testcase_04 AC 71 ms
134,228 KB
testcase_05 AC 71 ms
134,372 KB
testcase_06 AC 71 ms
134,380 KB
testcase_07 AC 100 ms
134,292 KB
testcase_08 AC 1,083 ms
167,228 KB
testcase_09 AC 1,097 ms
167,228 KB
testcase_10 AC 1,123 ms
167,304 KB
testcase_11 AC 1,103 ms
167,204 KB
testcase_12 AC 1,097 ms
167,116 KB
testcase_13 AC 1,110 ms
167,424 KB
testcase_14 AC 1,098 ms
167,296 KB
testcase_15 AC 1,092 ms
167,184 KB
testcase_16 AC 1,115 ms
167,168 KB
testcase_17 AC 1,097 ms
167,300 KB
testcase_18 AC 1,087 ms
167,080 KB
testcase_19 AC 1,091 ms
167,168 KB
testcase_20 AC 1,093 ms
167,280 KB
testcase_21 AC 1,094 ms
167,280 KB
testcase_22 AC 1,090 ms
167,116 KB
testcase_23 AC 1,062 ms
167,304 KB
testcase_24 AC 1,084 ms
167,168 KB
testcase_25 AC 1,076 ms
167,240 KB
testcase_26 AC 1,027 ms
164,888 KB
testcase_27 AC 1,002 ms
164,752 KB
testcase_28 AC 1,090 ms
164,736 KB
testcase_29 AC 983 ms
165,744 KB
testcase_30 AC 978 ms
165,760 KB
testcase_31 AC 963 ms
165,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


struct node {
	int mi;
	int S,T;
	vector<pair<int,int>> L,R;
	node() { mi=1<<20; S=-1; };
};

int N,K,Q;


template<class V,int NV> class SegTree_1 {
public:
	vector<V> val;
	V comp(V l,V r){
		if(l.S==-1) return r;
		if(r.S==-1) return l;
		V a;
		a.mi=min(l.mi,r.mi);
		a.S=l.S;
		a.T=r.T;
		
		a.L=l.L;
		a.R=r.R;
		int cur=0;
		if(a.L.size()) cur=a.L.back().first;
		FORR2(v,w,r.L) if((cur|v)!=cur) {
			cur|=v;
			if(cur==(1<<K)-1) {
				a.mi=min(a.mi,w-a.S+1);
				break;
			}
			a.L.push_back({cur,w});
		}
		cur=0;
		if(a.R.size()) cur=a.R.back().first;
		FORR2(v,w,l.R) if((cur|v)!=cur) {
			cur|=v;
			if(cur==(1<<K)-1) {
				a.mi=min(a.mi,a.T-w);
				break;
			}
			a.R.push_back({cur,w});
		}
		FORR2(x,y,l.R) FORR2(z,w,r.L) if((x|z)==(1<<K)-1) {
			a.mi=min(a.mi,w-y+1);
			break;
		}
		
		return a;
	};
	
	SegTree_1(){
		val=vector<V>(NV*2);
		int i;
		FOR(i,NV) {
			val[NV+i].S=i;
			val[NV+i].T=i+1;
			val[NV+i].mi=1<<20;
		}
	};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return node();
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, int v) {
		entry += NV;
		
		if(v==0) {
			val[entry].mi=1<<20;
			val[entry].L.clear();
			val[entry].R.clear();
		}
		else if(v==(1<<K)-1) {
			val[entry].mi=1;
			val[entry].L.clear();
			val[entry].R.clear();
		}
		else {
			val[entry].mi=1<<20;
			val[entry].L={{v,entry-NV}};
			val[entry].R={{v,entry-NV}};
		}
		val[entry].S=entry-NV;
		val[entry].T=entry-NV+1;
		
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_1<node,1<<20> st;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>x;
		st.update(i,x);
	}
	cin>>Q;
	while(Q--) {
		cin>>i>>x>>y;
		if(i==1) {
			st.update(x-1,y);
		}
		else {
			auto p=st.getval(x-1,y);
			if(p.mi>=1<<20) {
				cout<<-1<<endl;
			}
			else {
				cout<<p.mi<<endl;
			}
		}
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0