結果

問題 No.469 区間加算と一致検索の問題
ユーザー 👑 kmjpkmjp
提出日時 2016-12-19 00:19:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 214 ms / 5,000 ms
コード長 1,835 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 161,196 KB
実行使用メモリ 21,380 KB
最終ジャッジ日時 2023-08-23 13:17:38
合計ジャッジ時間 9,285 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
14,332 KB
testcase_01 AC 24 ms
14,268 KB
testcase_02 AC 23 ms
14,444 KB
testcase_03 AC 28 ms
14,644 KB
testcase_04 AC 29 ms
14,852 KB
testcase_05 AC 30 ms
14,808 KB
testcase_06 AC 31 ms
14,844 KB
testcase_07 AC 32 ms
14,968 KB
testcase_08 AC 31 ms
15,124 KB
testcase_09 AC 27 ms
14,576 KB
testcase_10 AC 29 ms
14,760 KB
testcase_11 AC 26 ms
14,488 KB
testcase_12 AC 32 ms
14,948 KB
testcase_13 AC 29 ms
14,908 KB
testcase_14 AC 25 ms
14,516 KB
testcase_15 AC 26 ms
14,768 KB
testcase_16 AC 32 ms
14,936 KB
testcase_17 AC 31 ms
14,848 KB
testcase_18 AC 31 ms
14,840 KB
testcase_19 AC 26 ms
14,544 KB
testcase_20 AC 32 ms
15,024 KB
testcase_21 AC 25 ms
14,444 KB
testcase_22 AC 24 ms
14,460 KB
testcase_23 AC 91 ms
17,632 KB
testcase_24 AC 92 ms
17,588 KB
testcase_25 AC 89 ms
17,580 KB
testcase_26 AC 90 ms
17,640 KB
testcase_27 AC 89 ms
17,644 KB
testcase_28 AC 89 ms
17,512 KB
testcase_29 AC 91 ms
17,644 KB
testcase_30 AC 90 ms
17,464 KB
testcase_31 AC 91 ms
17,520 KB
testcase_32 AC 90 ms
17,492 KB
testcase_33 AC 213 ms
21,096 KB
testcase_34 AC 214 ms
21,100 KB
testcase_35 AC 214 ms
21,284 KB
testcase_36 AC 211 ms
21,380 KB
testcase_37 AC 213 ms
21,280 KB
testcase_38 AC 169 ms
19,536 KB
testcase_39 AC 171 ms
19,748 KB
testcase_40 AC 168 ms
19,504 KB
testcase_41 AC 175 ms
19,648 KB
testcase_42 AC 172 ms
19,740 KB
testcase_43 AC 174 ms
19,648 KB
testcase_44 AC 171 ms
19,744 KB
testcase_45 AC 166 ms
19,752 KB
testcase_46 AC 168 ms
19,792 KB
testcase_47 AC 170 ms
19,556 KB
testcase_48 AC 24 ms
14,344 KB
testcase_49 AC 24 ms
14,284 KB
testcase_50 AC 171 ms
19,620 KB
testcase_51 AC 172 ms
19,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;
vector<int> MP;
string S[101010];
int L[101010];
int R[101010];
int V[101010];

const int prime_max = 1000000;
int NP,prime[100000],divp[prime_max];

void cprime() {
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		prime[NP++]=i;
		for(ll j=1LL*i*i;j>i&&j<prime_max;j+=i) divp[j]=i;
	}
}

ll SP[2][202020];
ll mo[2]={1000000007,1000000009};


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	srand(clock());
	FOR(i,201000) {
		SP[0][i+1]=(SP[0][i]+prime[rand()%10000+10000])%mo[0];
		SP[1][i+1]=(SP[1][i]+prime[rand()%20000+20000])%mo[1];
	}
	
	
	MP.push_back(-1);
	cin>>N>>Q;
	FOR(i,Q) {
		cin>>S[i];
		if(S[i]=="!") {
			cin>>L[i]>>R[i]>>V[i];
			MP.push_back(L[i]);
			MP.push_back(R[i]);
		}
	}
	sort(ALL(MP));
	MP.erase(unique(ALL(MP)),MP.end());
	map<pair<ll,ll>,int> memo;
	
	ll v[2]={0,0};
	memo[{v[0],v[1]}]=0;
	FOR(i,Q) {
		if(S[i]=="!") {
			L[i]=lower_bound(ALL(MP),L[i])-MP.begin();
			R[i]=lower_bound(ALL(MP),R[i])-MP.begin();
			FOR(x,2) {
				v[x]+=(SP[x][R[i]]-SP[x][L[i]])*V[i];
				v[x]=(v[x]%mo[x]+mo[x])%mo[x];
			}
			if(memo.count({v[0],v[1]})==0) memo[{v[0],v[1]}]=i+1;
		}
		else {
			cout<<memo[{v[0],v[1]}]<<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);
	solve(); return 0;
}
0