ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214442 | #2767. 摆烂 | STASISZHY | 0 | 803ms | 16912kb | C++11 | 2.5kb | 2024-11-18 21:57:32 | 2024-11-19 08:35:48 |
answer
// Problem: D. 摆烂
// Contest: undefined - NOIP2024训练赛 08
// URL: http://www.noi.ac/contest/1160/problem/2767
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
//#define int long long
#define fi first
#define se second
#define PII pair<int, int>
using namespace std;
const int N = 2e6 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int n, m, q, ans;
int dp[N];
PII s[N];
vector<int> v;
struct Tree
{
int l, r;
int mn[3];
}tr[N << 2];
inline void pushdown(int x, int op)
{
tr[2 * x].mn[op] = min(tr[2 * x].mn[op], tr[x].mn[op]);
tr[2 * x + 1].mn[op] = min(tr[2 * x + 1].mn[op], tr[x].mn[op]);
// tr[x].mn[op] = min(tr[2 * x].mn[op], tr[2 * x + 1].mn[op]);
}
void build(int x, int l, int r)
{
tr[x].l = l, tr[x].r = r, tr[x].mn[0] = tr[x].mn[1] = INF;
if(l == r) return;
int mid = l + r >> 1;
build(2 * x, l, mid);
build(2 * x + 1, mid + 1, r);
}
void change(int x, int l, int r, int v, int op)
{
if(l > r) return;
if(tr[x].l >= l && tr[x].r <= r)
{
tr[x].mn[op] = min(tr[x].mn[op], v);
return;
}
pushdown(x, op);
int mid = tr[x].l + tr[x].r >> 1;
if(l <= mid) change(2 * x, l, r, v, op);
if(r > mid) change(2 * x + 1, l, r, v, op);
}
int query(int x, int p, int op)
{
if(tr[x].l == tr[x].r) return tr[x].mn[op];
pushdown(x, op);
int mid = tr[x].l + tr[x].r >> 1;
if(p <= mid) return query(2 * x, p, op);
else return query(2 * x + 1, p, op);
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> s[i].fi >> s[i].se;
while(v.size() && s[v.back()].se <= s[i].se) v.pop_back();
v.push_back(i);
}
for (int i = 1; i <= v.size(); i ++) s[i] = s[v[i - 1]];
n = v.size();
// for(int i = 1; i <= n; i ++) cout << s[i].fi << ' ' << s[i].se << '\n';
build(1, 1, n);
for(int i = 0; i <= n; i ++)
{
if(i) dp[i] = min(query(1, i, 0), query(1, i, 1) + s[i].fi);
// cout << dp[i] << ' ';
int id = lower_bound(s + 1, s + n + 1, make_pair(dp[i], 0)) - s;
change(1, i + 1, id - 1, dp[i] + 2 * s[i + 1].se, 0);
change(1, id, n, 2 * s[i + 1].se, 1);
// for(int j = 1; j <= n; j ++) cout << query(1, j, 0) << ' ';
// cout << '\n';
// for(int j = 1; j <= n; j ++) cout << query(1, j, 1) << ' ';
// cout << '\n';
}
cout << dp[n] << '\n';
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 16904kb
input:
20 12513359 382258501 49946422 294259408 61782741 259996549 128874560 457675284 152578248 511428369 ...
output:
-1495608183
result:
wrong answer 1st numbers differ - expected: '2781551734', found: '-1495608183'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 0ms
memory: 16912kb
input:
1000 132699 718470029 234343 395421925 1290414 393017296 1399642 607415822 1402810 515471990 2008288...
output:
-1242072849
result:
wrong answer 1st numbers differ - expected: '2991845504', found: '-1242072849'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 12ms
memory: 16912kb
input:
100000 9326 430414358 13368 156324232 15149 550951304 22296 345034579 22578 397947033 37137 49312905...
output:
-1233895153
result:
wrong answer 1st numbers differ - expected: '2999984291', found: '-1233895153'
Subtask #4:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 397ms
memory: 16908kb
input:
2000000 181 24185667 293 532288461 1433 921996635 1694 629544979 2540 173534643 2662 963172401 3159 ...
output:
-1233860407
result:
wrong answer 1st numbers differ - expected: '2999999604', found: '-1233860407'
Subtask #5:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 390ms
memory: 16912kb
input:
2000000 684 624071334 1181 709831992 1397 43325781 1938 430417709 4157 60566309 4568 912818933 5265 ...
output:
-1233858379
result:
wrong answer 1st numbers differ - expected: '2999999891', found: '-1233858379'