比赛 |
4043级2023省选模拟赛1 |
评测结果 |
WWWWWWWWWWWWWWWWWWWW |
题目名称 |
贪玩蓝月 |
最终得分 |
0 |
用户昵称 |
yrtiop |
运行时间 |
2.105 s |
代码语言 |
C++ |
内存使用 |
205.77 MiB |
提交时间 |
2023-03-20 22:01:26 |
显示代码纯文本
#include <bits/stdc++.h>
#define pb emplace_back
using i64 = long long;
const int maxn = 5e4 + 5;
const int maxm = 505;
int C,n,p;
struct node {
int op,l,r,x,y;
node() {
op = l = r = x = y = 0;
}
node(int op,int l,int r,int x,int y):op(op),l(l),r(r),x(x),y(y){}
} Q[maxn];
int lst[maxn];
std::deque<int> q;
int ls[maxn << 2],rs[maxn << 2],cnt;
i64 f[maxn][maxm];
std::vector<int> G[maxn << 2];
void build(int i,int l,int r) {
ls[i] = l;
rs[i] = r;
G[i].clear();
if(l == r)
return ;
int mid = (l + r) >> 1;
build(i << 1 , l , mid);
build(i << 1 | 1 , mid + 1 , r);
return ;
}
void modify(int i,int l,int r,int x) {
if(l > r)
return ;
if(ls[i] >= l&&rs[i] <= r)
return G[i].pb(x),void();
int mid = (ls[i] + rs[i]) >> 1;
if(l <= mid)
modify(i << 1 , l , r , x);
else
modify(i << 1 | 1 , l , r , x);
return ;
}
void chkmax(i64& x,i64 y) {
if(y > x)
x = y;
return ;
}
void query(int i) {
int tmp = cnt;
for(int k = 0;k < (int)G[i].size();++ k)
for(int q = 0;q < p;++ q)
chkmax(f[cnt + k + 1][(q + G[i][k]) % p] , f[cnt + k][q] + (i64)G[i][k]);
cnt += G[i].size();
if(ls[i] == rs[i]) {
if(Q[ls[i]].op == 2) {
i64 ans = 0;
for(int j = Q[ls[i]].l;j <= Q[ls[i]].r;++ j)
chkmax(ans , f[cnt][j]);
printf("%lld\n",ans);
}
return ;
}
query(i << 1);
query(i << 1 | 1);
cnt = tmp;
return ;
}
int main() {
freopen("tanwan.in","r",stdin);
freopen("tanwan.out","w",stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> C >> n >> p;
for(int i = 1;i <= n;++ i) {
std::string s;
std::cin >> s;
if(s == "IF") {
Q[i].op = 1;
std::cin >> Q[i].x >> Q[i].y;
q.push_front(i);
}
else if(s == "IG") {
Q[i].op = 1;
std::cin >> Q[i].x >> Q[i].y;
q.push_back(i);
}
else if(s == "DF") {
lst[q.front()] = i;
q.pop_front();
}
else if(s == "DG") {
lst[q.back()] = i;
q.pop_back();
}
else {
Q[i].op = 2;
std::cin >> Q[i].l >> Q[i].r;
}
}
while(!q.empty())
lst[q.front()] = n + 1,q.pop_front();
build(1 , 1 , n);
for(int i = 1;i <= n;++ i)
if(Q[i].op == 1)
modify(1 , i , lst[i] - 1 , Q[i].y);
query(1);
return 0;
}