100+100+100+100+30=430
T1
模拟
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
while(k--){
int x,y;
string s;
cin>>x>>y>>s;
for(auto c:s){
if(c=='f'){
int nx = x,ny = y+1;
if(nx<=0||nx>n||ny<=0||ny>n) continue;
x = nx,y = ny;
}else if(c=='l'){
int nx = x-1,ny = y;
if(nx<=0||nx>n||ny<=0||ny>n) continue;
x = nx,y = ny;
}else if(c=='r'){
int nx = x+1,ny = y;
if(nx<=0||nx>n||ny<=0||ny>n) continue;
x = nx,y = ny;
}else{
int nx = x,ny = y-1;
if(nx<=0||nx>n||ny<=0||ny>n) continue;
x = nx,y = ny;
}
}
cout<<x<<" "<<y<<endl;
}
}
T2
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int n;
int main(){
cin>>n;
vector<int> a(n+1);
vector<int> b(n+1);
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
vector<int> dp(n+2);
dp[n+1] = 0;
for(int i=n;i>=0;i--){
dp[i] = max(0,dp[i+1]+a[i]-b[i]);
}
vector<int> sumb(n+1,0);
for(int i=1;i<n;i++){
sumb[i] += sumb[i-1] + max(0,b[i]-(dp[i+1]+a[i]));
}
vector<int> ans(n+1);
for(int i=1;i<=n;i++){
int add = min(b[i],dp[i+1]+a[i]);
ans[i] = dp[0] + max(0,add - sumb[i-1]);
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
}
T3
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int n,N,q;
struct node{
int timestamp;
int data;
int valid;//wright?
};
int main(){
cin>>n>>N>>q;
set<pii> S[N];
map<int,pii> mp;
int timestamp = 0;
while(q--){
++timestamp;
int o,a;
cin>>o>>a;
int group = (a/n)%N;
auto state = mp.find(a);
auto &s = S[group];
if(state == mp.end()){
int x = o==1?1:0;
mp[a] = {timestamp,x};
//cout<<"query:"<<o<<" "<<a<<" "<<s.size()<<endl;
if(s.size()>=n){
pii f = *(s.begin());
auto [t,w] = mp[f.second];
//cout<<"delete:"<<f.second<<" "<<t<<" "<<w<<endl;
if(w==1) cout<<"1 "<<f.second<<endl;
mp.erase(f.second);
s.erase(s.begin());
}
cout<<"0 "<<a<<endl;
s.insert({timestamp,a});
}else{
int t = mp[a].first;
s.erase({t,a});
mp[a].first = timestamp;
if(o==1) mp[a].second = 1;
s.insert({timestamp,a});
}
}
}
T4
蒙的,不包对
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
vector<vector<pii>> g;
vector<int> dist;
vector<bool> vis;
int n;
vector<int> a,k;
void dijkstra(){
priority_queue<pii,vector<pii>,greater<pii> > pq;
pq.push({0,1});
dist[1] = 0;
while(pq.size()){
auto [dis,ver] = pq.top();
pq.pop();
if(vis[ver]) continue;
vis[ver] = true;
for(auto [v,w]:g[ver]){
if(dist[v] > dis+ w){
dist[v] = dis + w;
pq.push({dis+w,v});
}
}
}
}
int main(){
cin>>n;
g = vector<vector<pii>>(n+1);
dist = vector<int>(n+1,1e9);
a = vector<int>(n+1);
k = vector<int>(n+1);
vis = vector<bool>(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>k[i];
}
vector<pii> seg(n);
for(int i=1;i<n;i++){
seg[i] = {min(n,i+k[i]),i};
}
sort(seg.begin()+1,seg.end());
vector<pii> myseg;
int mxr = 0;
for(int i=1;i<n;i++){
auto [r,l] = seg[i];
if(i==1){
for(int j=mxr+1;j<=r;j++){
g[l].push_back({j-a[j],1});
}
mxr = r;
}else{
g[l].push_back({seg[i-1].second,0});
for(int j=mxr+1;j<=r;j++){
g[l].push_back({j-a[j],1});
}
mxr = r;
}
}
dijkstra();
if(dist[n]==1e9) dist[n] = -1;
cout<<dist[n]<<endl;
}
T5
暴力30分
#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const int N = 2e6+10;
int n;
int a0[N],b0[N];
int a[N],b[N];
int get_ans(int st){
int l = 0,r = 1e9;
auto check=[&](int x)->bool{
int lft = st,nxt = st+1;
int res = 0;
while(res<n){
bool flag = false;
if(lft>0){
if(x>=a[lft]){
x+=b[lft--];
res++;
flag = true;
continue;
}
}
if(nxt<=n){
if(x>=a[nxt]){
x+=b[nxt++];
res++;
continue;
}
}
return false;
}
return true;
};
while(l<r){
int mid = l+r>>1;
if(check(mid)) r = mid;
else l = mid+1;
}
return l;
}
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a0[i];
}
for(int i=1;i<=n;i++){
cin>>b0[i];
}
int q;
cin>>q;
while(q--){
memcpy(a,a0,sizeof a);
memcpy(b,b0,sizeof b);
int k; cin>>k;
while(k--){
int i,x,y;
cin>>i>>x>>y;
a[i] = x;b[i] = y;
}
int res =0 ;
for(int i=1;i<n;i++){
res^=get_ans(i);
}
cout<<res<<endl;
}
}