2.19杂
今天晚一做完物理之后冲机房,然后电脑寄了上不了网,换了一台上不了qq,最后换到了刑天遗留下来的电脑(刑天已经离开了我们……
电脑似乎刷过机,很干净……
去洛谷写了道小红题,一直TLE,然后发现快读写错了……
inline int read() {
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f = -1; char c = getchar(); }
while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}
昨天用了一天了没发现,我谔谔
写了个数据结构优化DP,写了依托答辩……调了许久
#include <bits/stdc++.h>
#define int long long
const int N = 250005;
const int M = 1000005;
const int INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
inline int read() {
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}
int n, T;
struct cow {
int st, ed;
bool operator< (const cow &y) const {
return ed < y.ed || (ed == y.ed && st < y.st);
}
}a[N];
struct node {
int l, r, dat;
#define lc p << 1
#define rc p << 1 | 1
}t[M << 2];
int f[M];
void pushup(int p) {
t[p].dat = min(t[lc].dat, t[rc].dat);
}
void build(int p, int l, int r) {
t[p].l = l, t[p].r = r;
if (l == r) {
t[p].dat = f[l];
return;
}
int mid = l + r >> 1;
build(lc, l, mid);
build(rc, mid + 1, r);
pushup(p);
}
void modify(int p, int x, int v) {
if (t[p].l == t[p].r) {
t[p].dat = v;
return;
}
int mid = t[p].l + t[p].r >> 1;
if(x <= mid) modify(lc, x, v);
else modify(rc, x, v);
pushup(p);
}
int query(int p, int l, int r) {
if(t[p].l >= l && t[p].r <= r) return t[p].dat;
int mid = t[p].l + t[p].r >> 1;
int res = INF;
if(l <= mid) res = min(res, query(lc, l, r));
if(r > mid) res = min(res, query(rc, l, r));
return res;
}
signed main() {
n = read(), T = read();
for (int i = 1; i <= n; i++) {
a[i].st = read(), a[i].ed = read();
a[i].st = max(a[i].st, 1ll);
a[i].ed = min(a[i].ed, T);
}
sort(a + 1, a + n + 1);
memset(f, 0x3f, sizeof(f));
f[0] = 0;
build(1, 0, T);
for (int i = 1; i <= n; i++) {
int l = a[i].st, r = a[i].ed;
if (l > r) continue;
int tmp = query(1, l - 1, r);
f[r] = min(f[r], tmp + 1);
modify(1, r, f[r]);
}
cout << (f[T] == INF ? -1 : f[T]);
}
最后摆烂罢!
打大雪花把电脑打抽烟了……
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫