結果

問題 No.2273 一点乗除区間積
ユーザー 👑 kmjpkmjp
提出日時 2023-04-23 23:13:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,409 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 202,444 KB
実行使用メモリ 18,324 KB
最終ジャッジ日時 2024-04-25 17:24:17
合計ジャッジ時間 9,331 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,208 KB
testcase_01 AC 4 ms
14,400 KB
testcase_02 AC 5 ms
14,736 KB
testcase_03 AC 4 ms
14,040 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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;}
//-------------------------------------------------------


int N,Q,C;
ll mo;
int S[20];
int num[101010][20];
vector<int> cand;
ll phi;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> bt[20];

template<class V, int ME> class BITm {
public:
	V bit[1<<ME];
	BITm(){ for(int i=0;i<1<<ME;i++) bit[i]=1;}
	V operator()(int e) {if(e<0) return 1;V s=1;e++;while(e) (s*=bit[e-1])%=mo,e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) (bit[e-1]*=v)%=mo,e+=e&-e;}
};
BITm<int,20> btm;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>mo>>Q;
	ll M=mo;
	phi=mo;
	for(i=2;i*i<=M;i++) if(M%i==0) {
		phi=phi/i*(i-1);
		cand.push_back(i);
		while(M%i==0) {
			S[C]++;
			M/=i;
		}
		C++;
	}
	if(M>1) {
		cand.push_back(M);
		S[C]=1;
		C++;
	}
		
	
	FOR(i,N) {
		ll a;
		cin>>a;
		FOR(j,C) {
			while(a%cand[j]==0) a/=cand[j], num[i][j]++;
			bt[j].add(i,num[i][j]);
		}
		btm.add(i,a%mo);
	}
	while(Q--) {
		int J,M,A,B;
		cin>>J>>M>>A>>B;
		int ok=0;
		if(M==mo) {
			ok=1;
			FOR(i,C) if(num[J][i]<S[i]) ok=0;
		}
		if(ok==0) {
			FOR(i,C) while(M%cand[i]==0) {
				M/=cand[i];
				num[J][i]++;
				bt[i].add(J,1);
			}
			btm.add(i,M%mo);
		}
		else {
			FOR(i,C) {
				num[J][i]-=S[i];
				bt[i].add(J,-S[i]);
			}
		}
		
		ll a=btm(B)*modpow(btm(A-1),phi-1)%mo;
		FOR(j,C) {
			ll b=modpow(cand[j],bt[j](B)-bt[j](A-1));
			a=a*b%mo;
		}
		cout<<a<<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