結果

問題 No.2273 一点乗除区間積
ユーザー 沙耶花沙耶花
提出日時 2023-04-14 22:27:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,813 bytes
コンパイル時間 4,968 ms
コンパイル使用メモリ 263,364 KB
実行使用メモリ 48,640 KB
最終ジャッジ日時 2024-04-18 19:57:55
合計ジャッジ時間 10,131 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 330 ms
5,376 KB
testcase_19 AC 301 ms
14,336 KB
testcase_20 AC 678 ms
25,856 KB
testcase_21 AC 870 ms
48,640 KB
testcase_22 AC 677 ms
25,836 KB
testcase_23 AC 668 ms
25,884 KB
testcase_24 AC 612 ms
25,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
long long B;
using P = pair<long long,vector<long long>>;
vector<long long> ps;
P op(P a,P b){
	a.first *= b.first;
	a.first %= B;
	rep(i,a.second.size())a.second[i] += b.second[i];
	return a;
}

P e(){
	return make_pair(1LL,vector<long long>(ps.size()+1,0));
}


int main(){
	int n,q;
	cin>>n>>B>>q;
	vector<int> c;
	{
		long long b = B;
		for(long long i=2;i*i<=b;i++){
			if(b%i==0){
				ps.push_back(i);
				c.push_back(0);
				while(b%i==0){
					b/=i;
					c.back()++;
				}
			}
		}
		
		if(b!=1){
			ps.push_back(b);
			c.push_back(1);
		}
	}
	
	vector<P> a(n,e());
	rep(i,n){
		long long t;
		cin>>t;
		rep(j,ps.size()){
			while(t!=0 && t%ps[j]==0){
				t /= ps[j];
				a[i].second[j]++;
			}
		}
		if(t!=0){
			a[i].first = t;
		}
		else{
			a[i].first = 1;
			a[i].second.back() = 1;
		}
	}
	segtree<P,op,e> seg(a);
	rep(_,q){
		long long x,y,z,w;
		cin>>x>>y>>z>>w;
		auto t = seg.get(x);
		bool f = false;
		if(y==B){
			f = true;
			if(t.second.back()>0){
			}
			else{
				rep(i,ps.size()){
					if(c[i]>t.second[i])f = false;
				}
			}
		}
		if(f){
			if(t.second.back()>0)t.second.back()--;
			else{
				rep(i,ps.size())t.second[i] -= c[i];
			}
		}
		else{
			rep(i,ps.size()){
				while(y!=0 && y%ps[i]==0){
					y /=ps[i];
					t.second[i]++;
				}
			}
			if(y==0)t.second.back()++;
			else{
				t.first *= y;
				t.first %= B;
			}
		}
		seg.set(x,t);
		t = seg.prod(z,w+1);
		long long ans = t.first;
		rep(i,ps.size()){
			ans *= pow_mod(ps[i],t.second[i],B);
			ans %= B;
		}
		if(t.second.back()!=0)ans = 0;
		cout<<ans<<endl;
	}
	
	return 0;
}
0