比赛 |
2025.3.8 |
评测结果 |
AAAAAAAATTTTTT |
题目名称 |
线段覆盖 |
最终得分 |
57 |
用户昵称 |
LikableP |
运行时间 |
13.413 s |
代码语言 |
C++ |
内存使用 |
3.52 MiB |
提交时间 |
2025-03-08 10:25:45 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <fstream>
using namespace std;
const int MAXN = 2e5 + 10;
int L, n;
int a[MAXN];
int main() {
freopen("xdfg.in", "r", stdin);
freopen("xdfg.out", "w", stdout);
scanf("%d %d", &L, &n);
while (n--) {
int m, s, t;
scanf("%d %d %d", &m, &s, &t);
if (m == 1) for (int i = s; i < s + t; ++i) a[i]++;
else for (int i = s; i < s + t; ++i) a[i]--;
int ans1 = 0, ans2 = 0;
for (int i = 1; i <= L; ++i) {
if (a[i]) {
ans2++;
if (!a[i - 1]) ans1++;
}
}
printf("%d %d\n", ans1, ans2);
}
return 0;
}
/*
老师我算了算,用我想的线段树的办法还不如用暴力。。。
实在想不到区间修改的时候怎么处理。。。
0
0 0
0 0 0
0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0
*/
/*
#include <iostream>
#include <cstdio>
#include <fstream>
#define ls(root) root << 1
#define rs(root) root << 1 | 1
using namespace std;
const int MAXN = 2e5 + 10;
int L, n;
int tree[MAXN << 2][2], lazy[MAXN << 2];
void Modify(int root, int lt, int rt, int lq, int rq, int val) {
if (lt == rt && lq == rq) {
lazy[root] += val;
return ;
}
int mid = lt + ((rt - lt) >> 1);
if (rq <= mid) {
Modify(ls(root), lt, mid, lq, rq, val);
} else if (lq > mid) {
Modify(rs(root), mid + 1, rt, lq, rq, val);
} else {
Modify(ls(root), lt, mid, lq, mid, val);
Modify(rs(root), mid + 1, rt, mid + 1, rq, val);
}
}
void Query() {
int sum = GetSum(1, 1, n, 1, n);
}
int main() {
scanf("%d %d", &L, &n);
while (n--) {
int m, a, t;
scanf("%d %d %d", &m, &a, &t);
if (m == 1) {
Modify(1, 1, n, a, a + t - 1, 1);
} else {
Modify(1, 1, n, a, a + t - 1, 1);
}
Query();
}
return 0;
} */