QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739154#9543. Good Partitionsnodnodnod123WA 124ms14472kbC++141.9kb2024-11-12 21:02:212024-11-12 21:02:22

Judging History

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

  • [2024-11-12 21:02:22]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:14472kb
  • [2024-11-12 21:02:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10, INF = 0x3f3f3f3f;
int cnt[N];
ll n, m;
struct node {
	int l, r, val;
}tr[N*4];
void build(int root, int l, int r) { //建树
	tr[root].l = l; tr[root].r = r; tr[root].val = 0;
	if (l != r) {
		int mid = (l + r) / 2;
		build(root * 2, l, mid);
		build(root * 2+1, mid+1,r);
	}
}
int gcd(int a, int b) {
	if (b == 0)return a;
	else return gcd(b, a % b);
}
void update(int o,int x,int v) {
	if (tr[o].l == tr[o].r) { tr[o].val = v;
	return; }
	int mid = (tr[o].l + tr[o].r) / 2;
	if(x<=mid)update(o * 2,x, v);
	else update(o * 2+1,x, v);
	tr[o].val = gcd(tr[o * 2].val, tr[o * 2 + 1].val);
	//cout << o * 2 << " " << tr[o * 2].l << " " << tr[o * 2].r << " " << tr[o * 2].val << endl;
	//cout << o * 2 + 1 << " " << tr[o * 2 + 1].l << " " << tr[o * 2 + 1].r << " " << tr[o * 2 + 1].val << endl;
	//cout << o << " " << tr[o].l << " " << tr[o].r << " " << tr[o].val << endl;
}
void solve() {
	cin >> n >> m;
	build(1, 1, n);
	vector<ll>a(n+5);
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (ll i = 1; i < n; i++) {
		if (a[i] > a[i + 1])update(1, i, i);
	}
	if (tr[1].val == 0)cout << n << endl;
	else cout << cnt[tr[1].val] << endl;
	while (m--) {
		ll ii, jj; cin >> ii >> jj;
		 a[ii] = jj;
		if (a[ii - 1] > a[ii])update(1, ii - 1, ii - 1);
		else update(1, ii - 1, 0);
		if (ii + 1 <= n) {
			if (a[ii] > a[ii + 1])update(1, ii, ii);
			else update(1, ii, 0);
		}
		if (tr[1].val == 0)cout << n << endl;
		else cout << cnt[tr[1].val] << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	for (int i = 1; i <= 10000; i++)
	{	for (int j = 1; j * i <= 10000; j++)
		{
		if (i * j < N)cnt[i * j] ++;  //预处理数的因数个数
		else break;
	    }
    }
    int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3684kb

input:

1
5 2
4 3 2 6 1
2 5
3 5

output:

1
2
3

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

1
1 1
2000000000
1 1999999999

output:

1
1

result:

ok 2 lines

Test #3:

score: -100
Wrong Answer
time: 124ms
memory: 14472kb

input:

1
200000 200000
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
200000
0
2...

result:

wrong answer 1st lines differ - expected: '160', found: '0'