QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505779#9104. Zayin and ForestWendyChenRE 0ms0kbC++201.6kb2024-08-05 11:17:502024-08-05 11:17:50

Judging History

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

  • [2024-08-05 11:17:50]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-05 11:17:50]
  • 提交

answer

#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define endl '\n'
#define base 191
#define mod 1145141
const int N = 1e7 + 10;
int n, m;
int tree[N];
int op[N], opa[N], opb[N];
vector<int> nums;
int lowbit(int x) {
	return x & -x;
}

void add(int pos, int val) { // tree为树状数组
	while (pos <= n) { // 不能越界
		tree[pos] += val;
		pos += lowbit(pos);
	}
}

int query(int x) { // a[1]..a[x]的和
	int ans = 0;
	while (x >= 1) {
		ans = ans + tree[x];
		x = x - lowbit(x);
	}
	return ans;
}

int query(int l, int r) { // 前缀相减
	return query(r) - query(l - 1);//求的是(l,r)里面的所有数的和
}


void solve() {
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> op[i] >> opa[i] >> opb[i];
		if (op[i] == 1) {
			for(int j = opa[i]; j <= n; j += lowbit(j)) {
				nums.push_back(j);
			}
		}
		else {
			nums.push_back(opa[i]);
			nums.push_back(opb[i]);
		}
	}
	sort(nums.begin(), nums.end());
	nums.erase(unique(nums.begin(), nums.end()), nums.end());
	for (int i = 1; i <= m; ++i) {
		if (op[i] == 1) {
			for (int j = opa[i]; j <= n; j += lowbit(j)) {
				int y = lower_bound(nums.begin(), nums.end(), j) - nums.begin() + 1;
				add(y, opb[i]);
			}
		}
		else {
			int l = lower_bound(nums.begin(), nums.end(), opa[i]) - nums.begin() + 1;
			int r = lower_bound(nums.begin(), nums.end(), opb[i]) - nums.begin() + 1;
			cout << query(l, r) << endl;
		}
	}
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T = 1;
	//cin >> T;
	while (T--) {
		solve();
	}
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

1000000000 20000
2 384578735 526547442
1 64211261 592970906
1 512065247 448267721
1 44993150 127180320
1 880319036 927623947
1 170536687 572121854
1 896600029 804033011
1 666246328 754201635
1 654066651 179982083
2 240989825 984888006
2 372004567 858916479
2 76127818 98606736
1 181794163 902842353
1...

output:


result: