QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865104 | #9409. Sensors | yeweiliang | RE | 15ms | 127216kb | C++14 | 2.3kb | 2025-01-21 14:53:04 | 2025-01-21 14:53:04 |
Judging History
answer
#include<bits/stdc++.h>
#define ls (k<<1)
#define rs (k<<1|1)
using namespace std;
const int N=5e5+5;
int T,n,m,x,l[N],r[N];
long long ans;
vector<pair<int,int> > a[N];
set<int> s;
struct node{
int l,r;
vector<int> g;
vector<long long> s;
}t[N<<2];
void push_up(int k){
int i=0,j=0;
while(i<t[ls].g.size()&&j<t[rs].g.size()){
if(t[ls].g[i]<t[rs].g[j]) t[k].g.push_back(t[ls].g[i]),t[k].s.push_back(t[ls].s[i++]);
else t[k].g.push_back(t[rs].g[j]),t[k].g.push_back(t[rs].s[j++]);
}
while(i<t[ls].g.size()) t[k].g.push_back(t[ls].g[i]),t[k].s.push_back(t[ls].s[i++]);
while(j<t[rs].g.size()) t[k].g.push_back(t[rs].g[j]),t[k].s.push_back(t[rs].s[j++]);
}
void build(int k,int l,int r){
t[k].l=l;
t[k].r=r;
t[k].g.clear();
t[k].s.clear();
if(l==r){
for(int i=0;i<a[l].size();i++) t[k].g.push_back(a[l][i].first),t[k].s.push_back(1ll*a[l][i].second*a[l][i].second);
return;
}
int mid=l+r>>1;
build(ls,l,mid);
build(rs,mid+1,r);
push_up(k);
}
void dfs(int k){
for(int i=1;i<t[k].s.size();i++) t[k].s[i]+=t[k].s[i-1];
if(t[k].l==t[k].r) return;
dfs(ls);
dfs(rs);
}
long long query(int k,int l1,int l2,int r1,int r2){
if(l1>l2||r1>r2||l2<t[k].l||t[k].r<l1||t[k].g.empty()) return 0;
if(l1<=t[k].l&&t[k].r<=l2){
int l=lower_bound(t[k].g.begin(),t[k].g.end(),r1)-t[k].g.begin(),r=upper_bound(t[k].g.begin(),t[k].g.end(),r2)-t[k].g.begin()-1;
if(r<0) return 0;
if(l) return t[k].s[r]-t[k].s[l-1];
return t[k].s[r];
}
return query(ls,l1,l2,r1,r2)+query(rs,l1,l2,r1,r2);
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) a[i].clear();
for(int i=1;i<=m;i++){
scanf("%d%d",&l[i],&r[i]);
a[l[i]].push_back(make_pair(r[i],i));
}
for(int i=0;i<n;i++) sort(a[i].begin(),a[i].end());
build(1,0,n-1);
dfs(1);
ans=0;
for(int i=1;i<=m;i++) if(l[i]==r[i]) ans+=i*i;
s.clear();
for(int i=-1;i<=n;i++) s.insert(i);
printf("%lld ",ans);
for(int i=0;i<n;i++){
scanf("%d",&x);
x=(1ll*x+ans)%n;
auto it=s.find(x);
ans-=query(1,(*prev(it,1))+1,x,x,(*next(it,1))-1);
if((*prev(it,1))!=-1) ans+=query(1,(*prev(it,2))+1,*prev(it,1),x,(*next(it,1)-1));
if((*next(it,1))!=-1) ans+=query(1,(*prev(it,1))+1,x,*next(it,1),(*next(it,2)-1));
s.erase(x);
printf("%lld ",ans);
}
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 127216kb
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:
133 220 185 0 0 1 0 0 0 0 0 4 4 5 4 0 0 4 4 4 4 5 0 91 0 0 0 0 0 1 0 13 13 4 0 1 0 168 249 105 137 137 137 0 4 13 9 0 0 1 1 0 79 127 -44 1 54 0 0 0 25 25 25 61 40 50 50 50 50 385 0 0 0 9 71 9 53 69 0 0 0 9 9 9 297 297 35 39 103079215070 -306 1 10 9 9 9 54 52 5 5 5 0 0 5 13 13 4 16 ...