如题,用的模拟法,假设每个人都一直往下走,直到没有剩下人或者没有剩下出口。
#include<bits/stdc++.h>
#define MAXN 20005
#define LONGN 10000000
#define check for(int I = 0;I < L;I++){cout << "no " << ot[I] << ",rt " << p[I] << endl;}
#define ckp cout<< rt << "/" << rta << endl;for(int I = 1;I <= n;I++){cout << I << ":" << b[I];if(s[I] == 0) {cout << " to " << b[I]+1 << endl;} else {cout << " to " << b[I]-1 << endl;}}cout << endl;
using namespace std;
int n,m,L,a[MAXN],l[MAXN],s[MAXN],b[MAXN],ans,otp,rt,rta;
int p[LONGN],ot[LONGN];
vector<int> mem;
int main() {
freopen("3.txt","r",stdin);
cin >> n >> m >> L;
for(int i = 2; i <= m; i++) {
scanf("%d",&a[i]);
}
for(int i = 1; i <= m; i++) {
scanf("%d",&l[i]);
p[a[i]] = l[i];
ot[a[i]] = i;
rta += l[i];
}
rt = rta;
for(int i = 1; i <= n; i++) {
scanf("%d%d",&s[i],&b[i]);
}
// check
// ckp
while(otp < n) {
// ckp
for(int i = 1; i <= n; i++) {
if(b[i] == -114 || b[i] == 666) {
continue;
}
if(s[i] == 0) {
b[i]++;
} else {
b[i]--;
}
if(b[i] < 0) {
b[i] = L-1;
}
if(b[i] >= L) {
b[i] = 0;
}
if(p[b[i]] > 0 || rt <= 0) {
p[b[i]]--;
if(rt <= 0){
mem.push_back(0);
b[i] = -666;
}
else{
mem.push_back(ot[b[i]]*i);
b[i] = -114;
}
otp++;
rt --;
}
}
}
ans = 0;
for(int i = 0;i < mem.size();i++){
ans ^= mem[i];
}
cout << ans;
return 0;
}