QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864809#9409. SensorslinxuanruiRE 0ms27092kbC++142.3kb2025-01-21 08:53:192025-01-21 08:53:20

Judging History

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

  • [2025-01-21 08:53:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:27092kb
  • [2025-01-21 08:53:19]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 5e5 + 5;
int qwq,n,m,l,r,k;
vector<pair<int,int> > tree[N];
set<int> st;
map<pair<int,int>,int> mp;
vector<int> sum[N];
#define lowbit(x) ((x) & (-x))
void update(int l,int r,int pos){
	for(int i = l;i <= n;i += lowbit(i))tree[i].push_back({r,pos * pos});
}
int query(int l,int r1,int r2){
	if(r1 > r2)return 0;
	int ans = 0;
	for(int i = l;i >= 1;i -= lowbit(i)){
		int posl = lower_bound(tree[i].begin(),tree[i].end(),make_pair(r1,0ll)) - tree[i].begin() - 1;
		int vall = (~posl ? sum[i][posl] : 0ll);
		int posr = upper_bound(tree[i].begin(),tree[i].end(),make_pair(r2,1145141919810ll)) - tree[i].begin() - 1;
		int valr = (~posr ? sum[i][posr] : 0ll);
		ans += valr - vall;
	}
//	cout << " " << l << " " << r1 << " " << r2 << " " << ans << endl;
	return ans;
}
int query(int l1,int l2,int r1,int r2){
	if(l1 > l2)return 0;
	return query(l2,r1,r2) - query(l1 - 1,r1,r2);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> qwq;
	while(qwq--){
		cin >> n >> m;
		st.clear(),mp.clear();
		for(int i = 1;i <= n;i++)tree[i].clear(),sum[i].clear();
		int lst = 0;
		for(int i = 1;i <= m;i++)cin >> l >> r,l++,r++,update(l,r,i),lst += (l == r) * i * i,mp[{l,r}] = i * i;
		for(int i = 1;i <= n;i++){
			st.insert(i);
			sort(tree[i].begin(),tree[i].end());
			if(tree[i].size()){
				sum[i].push_back(tree[i][0].second);
				for(int j = 1;j < tree[i].size();j++)sum[i].push_back(sum[i].back() + tree[i][j].second);
			}
		}
		cout << lst << " ";
		for(int i = 1;i <= n;i++){
			cin >> k;
			k = (k + lst) % n + 1;
			assert(st.find(k) != st.end());
			auto it = st.find(k);
			int x = (*it);
			int l = 0;
			if(it == st.begin())l = 1;
			else l = *prev(it,1) + 1;
			int r = 0;
			if(next(it,1) == st.end())r = n;
			else{
				r = *next(it,1) - 1;
				int r2 = 0;
				if(next(it,2) == st.end())r2 = n;
				else r2 = *next(it,2) - 1;
//				cout << "(" << l << " " << r + 1 << " " << r + 2 << ")" << query(l,r + 1,r + 1,r2) << " ";
				lst += query(l,r + 1,r + 1,r2) - mp[{r + 1,r + 1}];
			}
			lst -= query(l,x,x,r);
//			cout << "(" << l << " " << x << " " << r << ")" << query(l,x,x,r) << " " << lst << endl;
			st.erase(it);
			cout << lst << " ";
		}
		cout << endl;
	}
}

详细

Test #1:

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

input:

3
5 4
2 4
2 3
3 3
0 2
3 2 4 2 0
2 1
1 1
1 0
2 1
0 1
0 0

output:

9 13 29 17 16 0 
1 1 0 
0 1 0 

result:

ok 3 lines

Test #2:

score: -100
Runtime Error

input:

2227
2 9
0 1
1 1
0 1
0 0
0 1
0 1
0 0
1 1
0 1
1 1
3 1
0 2
1 2 2
8 2
0 2
3 5
7 4 0 3 2 6 4 1
6 2
1 3
0 1
0 0 5 1 4 2
1 6
0 0
0 0
0 0
0 0
0 0
0 0
0
5 1
1 4
0 1 2 3 3
5 3
0 3
4 4
2 2
0 4 0 0 0
5 10
0 2
3 3
1 3
1 4
1 3
0 4
2 4
0 0
0 1
4 4
3 1 3 4 1
8 4
0 5
0 1
6 7
3 4
1 3 3 5 2 3 5 3
2 7
1 1
0 0
0 0
1 1
...

output:


result: