标签:name val run 就删除 名称 getchar 获得 平衡树 read
Basketball 1 10 1
Accepted
1140
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int n, m;
int a[2005];
int main()
{
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
string t; cin >> t;
int u, v, w;
cin >> u >> v >> w;
for(int j = u; j <= v; j++) a[j] += w;
}
for(int i = 1; i <= 1440; i++)
{
n++, n -= a[i];
if(n <= 0) {cout << "Runtime Error\n" << i; return 0;}
}
cout << "Accepted\n" << n;
return 0;
}
5
1 2 3
4 5
10
Q 2
A 4 6
C 1 4
Q 2
A 2 1
A 3 3
A 1 3
Q 4
C 2 10
Q 1
4
5
-1
11
3
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define N 30005
using namespace std;
struct T {int l, r, val, dat, size;} t[N * 4];
int n, m, root, x, y, z, tot, now;
int a[N];
int read()
{
int x = 0; char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return x;
}
int New(int val)
{
t[++tot].val = val;
t[tot].dat = rand();
t[tot].size = 1;
return tot;
}
void up(int p) {t[p].size = t[t[p].l].size + t[t[p].r].size + 1;}
void split(int p, int val, int &x, int &y)
{
if(!p) {x = y = 0; return;}
if(t[p].val <= val) x = p, split(t[p].r, val, t[p].r, y);
else y = p, split(t[p].l, val, x, t[p].l);
up(p);
}
int merge(int x, int y)
{
if(!x || !y) return x + y;
if(t[x].dat > t[y].dat)
{
t[x].r = merge(t[x].r, y);
up(x); return x;
}
else
{
t[y].l = merge(x, t[y].l);
up(y); return y;
}
}
void insert(int val)
{
split(root, val - 1, x, y);
root = merge(merge(x, New(val)), y);
}
void erase(int val)
{
split(root, val, x, z);
split(x, val - 1, x, y);
y = merge(t[y].l, t[y].r);
root = merge(merge(x, y), z);
}
int valOfRank(int rank)
{
int p = root;
while(p)
{
if(t[t[p].l].size + 1 == rank) break;
else if(t[t[p].l].size >= rank) p = t[p].l;
else rank -= t[t[p].l].size + 1, p = t[p].r;
}
return t[p].val;
}
int main()
{
cin >> n, now = n;
for(int i = 1; i <= n; i++)
{
a[i] = read();
insert(a[i]);
}
cin >> m;
for(int i = 1; i <= m; i++)
{
char c[3]; scanf("%s", c);
if(c[0] == 'A')
{
int pos = read(), val = read();
erase(a[pos]);
a[pos] -= val;
if(a[pos] <= 0) now--;
else insert(a[pos]);
}
else if(c[0] == 'C')
{
int pos = read(), val = read();
erase(a[pos]);
a[pos] += val;
insert(a[pos]);
}
else if(c[0] == 'Q')
{
int rank = read();
if(now < rank) printf("-1\n");
else printf("%d\n", valOfRank(now - rank + 1));
}
}
cout << now;
return 0;
}
3 10
1 3 1 2 2
2 3 2 4 6
3 3 2 1 10
11
1
0
3
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 2005
using namespace std;
struct Ans {int id, lev;} ans[N];
struct A {int val, id, lev;} a[N][N];
int n, T;
int cnt[N];
int w[N][N], v[N][N], dp[N][N];
bool cmp(Ans x, Ans y) {return x.id < y.id;}
int main()
{
cin >> n >> T;
for(int i = 1; i <= n; i++)
{
int c; cin >> c;
int p; cin >> p;
cnt[i] = p;
for(int j = 1; j <= p; j++)
cin >> v[i][j], w[i][j] = c * j;
}
for(int i = 1; i <= n; i++)
for(int j = 0; j <= T; j++)
for(int k = 0; k <= cnt[i]; k++)
if(j - w[i][k] >= 0)
if(dp[i - 1][j - w[i][k]] + v[i][k] > dp[i][j])
{
dp[i][j] = dp[i - 1][j - w[i][k]] + v[i][k];
a[i][j].id = i, a[i][j].lev = k;
a[i][j].val = w[i][k];
}
else if(dp[i - 1][j - w[i][k]] + v[i][k] == dp[i][j] && w[i][k] < a[i][j].val)
{
dp[i][j] = dp[i - 1][j - w[i][k]] + v[i][k];
a[i][j].id = i, a[i][j].lev = k;
a[i][j].val = w[i][k];
}
cout << dp[n][T] << endl;
int now = T;
for(int i = n; i >= 1; i--)
{
ans[i].id = a[i][now].id;
ans[i].lev = a[i][now].lev;
now = now - a[i][now].val;
}
sort(ans + 1, ans + 1 + n, cmp);
for(int i = 1; i <= n; i++) cout << ans[i].lev << endl;
return 0;
}
标签:name val run 就删除 名称 getchar 获得 平衡树 read
原文地址:https://www.cnblogs.com/BigYellowDog/p/11620615.html