QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782396#9738. Make It DivisiblecbdsopaWA 1ms6840kbC++144.1kb2024-11-25 19:58:152024-11-25 19:58:17

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-25 19:58:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6840kb
  • [2024-11-25 19:58:15]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define db double
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define sky fflush(stdout)
#define gc getchar
#define pc putchar
namespace IO{
	template<class T>
	inline void read(T &s){
		s = 0;char ch = gc();bool f = 0;
		while(ch < '0' || '9'<ch) {if(ch == '-') f = 1; ch = gc();}
		while('0'<=ch && ch<='9') {s = s * 10 + (ch ^ 48); ch = gc();}
		if(ch == '.'){
			T p = 0.1;ch = gc();
			while('0' <= ch && ch <= '9') {s = s + p * (ch ^ 48);p /= 10;ch = gc();}
		}
		s = f ? -s : s;
	}
	template<class T,class ...A>
	inline void read(T &s,A &...a){
		read(s); read(a...);
	}
	template<class T>
	inline void print(T x){
		if(x<0) {x = -x; pc('-');}
		static char st[40];
		static int top;
		top = 0;
		do{st[++top] = x - x / 10 * 10 + '0';} while(x /= 10);
		while(top) {pc(st[top--]);}
	}
	template<class T,class ...A>
	inline void print(T s,A ...a){
		print(s); print(a...);
	}
};
using IO::read;
using IO::print;
const int N = 5e4;
int n, m;
int a[N + 3];
int gcd(int a, int b){
	if(!b) return a;
	return gcd(b, a % b);
}
struct SegTree{
	struct node{
		int Gcd;
	}t[N * 4 + 3];
	#define lc(x) (x << 1)
	#define rc(x) (x << 1 | 1)
	void pushup(int x){
		t[x].Gcd = gcd(t[lc(x)].Gcd, t[rc(x)].Gcd);
	}
	void build(int x, int l, int r){
		if(l == r){
			t[x].Gcd = a[l] - a[l - 1];
			return;
		}
		int mid = l + r >> 1;
		build(lc(x), l, mid);
		build(rc(x), mid + 1, r);
		pushup(x);
	}
	int query(int x, int l, int r, int L, int R){
		if(L > R) return 0;
		if(L <= l && r <= R){
			return t[x].Gcd;
		}
		int mid = l + r >> 1;
		int res = 0;
		if(L <= mid) res = gcd(res, query(lc(x), l, mid, L, R) );
		if(mid + 1 <= R) res = gcd(res, query(rc(x), mid + 1, r, L, R) );
		return res;
	}
}t;
int ch[N + 3][2];
int sta[N + 3], top;
int rt;
std::set<int>s[N + 3];
int l[N + 3], r[N + 3];
std::vector<std::pair<int, int> >tmp1;
std::vector<int>tmp2;
void calc(int x, int t, int sum){
	if(t == tmp1.size() ){
		tmp2.push_back(sum);
		return;
	}
	for(int i = 0; i <= tmp1[t].second; ++i){
		calc(x, t + 1, sum);
		sum *= tmp1[t].first;
	}
}
void dfs(int x){
	l[x] = r[x] = x;
	if(!ch[x][0] && !ch[x][1]){
		return;
	}
	for(int i = 0; i < 2; ++i){
		if(ch[x][i]){
			dfs(ch[x][i]);
			l[x] = std::min(l[x], l[ch[x][i] ]);
			r[x] = std::max(r[x], r[ch[x][i] ]);
		}
	}
	int g = t.query(1, 1, n, l[x] + 1, r[x]);
	int k = abs(g);
	tmp1.clear();
	tmp2.clear();
	for(int i = 2; i * i <= k; ++i){
		if(k % i == 0){
			int cnt = 0;
			while(k % i == 0) k /= i, ++cnt;
			tmp1.push_back({i, cnt});
		}
	}
	if(k != 1) tmp1.push_back({k, 1});
	//fprintf(stderr, "%d -> %d %d [%d, %d] %d\n", x, ch[x][0], ch[x][1], l[x], r[x], g);
	calc(x, 0, 1);
	for(auto it : tmp2){
		if(it - a[x] < 1 || it - a[x] > m) continue;
		//fprintf(stderr, "%d(%d) ", it - a[x], it);
		if((a[l[x] ] + it - a[x]) % it == 0){
			//fprintf(stderr, "<- ");
			bool flag = 1;
			if(ch[ch[x][0] ][0] || ch[ch[x][0] ][1])
			if(ch[x][0] && s[ch[x][0] ].find(it - a[x]) == s[ch[x][0] ].end() ) 
				flag = 0;
			if(ch[ch[x][1] ][0] || ch[ch[x][1] ][1])
			if(ch[x][1] && s[ch[x][1] ].find(it - a[x]) == s[ch[x][1] ].end() ) 
				flag = 0;
			if(flag) s[x].insert(it - a[x]);
		}
	}
	/*
	fprintf(stderr,"\n");
	for(auto it : s[x]){
		fprintf(stderr, "%d ",it);
	}fprintf(stderr, "\n");
	*/
}
inline void solve(){
	read(n, m);
	for(int i = 1; i <= n; ++i){
		read(a[i]);
		s[i].clear();
		ch[i][0] = ch[i][1] = 0;
	}
	if(n == 1){
		printf("%d %lld\n", m, 1ll * (m + 1) * m / 2);
		return;
	}
	t.build(1, 1, n);
	top = 0;
	sta[++top] = 1;
	for(int i = 2; i <= n; ++i){
		int k = top;
		while(k && a[sta[k] ] > a[i]) 
			--k;
		if(k < top) ch[i][0] = sta[k + 1];
		if(k) ch[sta[k] ][1] = i;
		sta[++k] = i;
		top = k;
	}
	rt = sta[1];
	dfs(rt);
	ll sum = 0; 
	for(auto it :s[rt]){
		sum += it;
	}
	printf("%d %lld\n", s[rt].size(), sum);
}
int main(){
#ifdef LOCAL
	file(a);
#endif
	int T; read(T);
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6808kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
100 5050

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 6840kb

input:

4
201 1000000000
1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...

output:

0 0
0 0
0 0
0 0

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 6356kb

input:

500
4 1000000000
8 14 24 18
4 1000000000
17 10 18 14
4 1000000000
6 17 19 19
4 1000000000
15 14 15 25
4 1000000000
16 16 5 25
4 1000000000
4 30 20 5
4 1000000000
11 4 23 9
4 1000000000
14 25 13 2
4 1000000000
18 18 1 15
4 1000000000
22 22 22 28
4 1000000000
15 17 17 10
4 1000000000
22 14 13 25
4 100...

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

wrong answer 78th lines differ - expected: '2 4', found: '0 0'