# Codeforces Round #310 (Div. 1) A B C D题

754人阅读 评论(0)

A题：

n（2*10^5）个大小不同的套娃  按照小的能套在大的里面的规则  已经按输入顺序套好了m个  问  最少拆、套几次可以形成1在2里 2在3里……n-1在n里  这种情况

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long LL;
#define N 200010

int n, m, now;

int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int p;
scanf("%d", &p);
for (int j = 1; j <= p; j++) {
int x;
scanf("%d", &x);
if (x == j) now++;
}
}
printf("%d\n", n - now - m + 1 + n - now);
return 0;
}

B题：

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long LL;
#define N 200010

int n, m, cnt;
int ans[N];

struct bridge {
LL l;
int id;

bool operator<(const bridge ff) const {
return l < ff.l;
}
} b[N];

struct section {
LL l, r, id;

bool operator<(const section ff) const {
return l < ff.l;
}
} s[N];

struct node {
int id;
LL r;

node() {

}

node(LL r, int id) {
this->r = r;
this->id = id;
}

bool operator<(const node ff) const {
return r > ff.r;
}
};
priority_queue<node> qu;

int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%I64d%I64d", &s[i].l, &s[i].r);
for (int i = 1; i < n; i++) {
LL tmpl, tmpr;
tmpr = s[i + 1].r - s[i].l;
tmpl = s[i + 1].l - s[i].r;
s[i].l = tmpl;
s[i].r = tmpr;
s[i].id = i;
}
sort(s + 1, s + n);
for (int i = 1; i <= m; i++) {
scanf("%I64d", &b[i].l);
b[i].id = i;
}
sort(b + 1, b + m + 1);
int idx = 1;
for (int i = 1; i <= m; i++) {
while (idx < n && s[idx].l <= b[i].l) {
qu.push(node(s[idx].r, s[idx].id));
idx++;
}
if (qu.empty()) continue;
node x = qu.top();
qu.pop();
if (x.r < b[i].l) break;
cnt++;
ans[x.id] = b[i].id;
}
if (cnt == n - 1) {
puts("Yes");
printf("%d", ans[1]);
for (int i = 2; i < n; i++) printf(" %d", ans[i]);
puts("");
} else puts("No");
return 0;
}

C题：

n*n(10^9)的格子  按/方向对角线划开  保留左上部分  m(2*10^5)个询问  每次在/对角线上选一点  向左或向上延伸到最近的空格  并将路线上的格子变成空格  输出变成空格的格子数

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long LL;
#define N 200010
#define L(x) (x<<1)
#define R(x) ((x<<1)|1)
#define MID(x,y) ((x+y)>>1)

int n, m;

struct ops {
int x, y, to;
} op[N];
int x[N], y[N], vis[N];

struct tree {
int l, r, lazy, near;
} f[2][N << 2];

void init(int l, int r, int i) {
for (int j = 0; j < 2; j++) {
f[j][i].l = l;
f[j][i].r = r;
f[j][i].near = f[j][i].lazy = 0;
}
if (l == r) return;
int mid = MID(l, r);
init(l, mid, L(i));
init(mid + 1, r, R(i));
}

void down(int i, int j) {
if (f[j][i].lazy) {
f[j][L(i)].lazy = max(f[j][L(i)].lazy, f[j][i].lazy);
f[j][L(i)].near = max(f[j][L(i)].near, f[j][i].lazy);
f[j][R(i)].lazy = max(f[j][R(i)].lazy, f[j][i].lazy);
f[j][R(i)].near = max(f[j][R(i)].near, f[j][i].lazy);
f[j][i].lazy = 0;
}
}

void update(int l, int r, int i, int j, int key) {
if (f[j][i].l == l && f[j][i].r == r) {
f[j][i].near = max(f[j][i].near, key);
f[j][i].lazy = max(f[j][i].lazy, key);
return;
}
down(i, j);
int mid = MID(f[j][i].l, f[j][i].r);
if (r <= mid) update(l, r, L(i), j, key);
else if (l > mid) update(l, r, R(i), j, key);
else {
update(l, mid, L(i), j, key);
update(mid + 1, r, R(i), j, key);
}
}

int query(int p, int i, int j) {
if (f[j][i].l == f[j][i].r) return f[j][i].near;
down(i, j);
int mid = MID(f[j][i].l, f[j][i].r);
if (p <= mid) return query(p, L(i), j);
else return query(p, R(i), j);
}

int main() {
char UL[5];
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d%s", &op[i].x, &op[i].y, UL);
x[i] = op[i].x;
y[i] = op[i].y;
if (UL[0] == 'U') op[i].to = 0;
else op[i].to = 1;
}
sort(x + 1, x + m + 1);
sort(y + 1, y + m + 1);
for (int i = 1; i <= m; i++) {
op[i].x = lower_bound(x + 1, x + m + 1, op[i].x) - x;
op[i].y = lower_bound(y + 1, y + m + 1, op[i].y) - y;
}
init(1, m, 1);
for (int i = 1; i <= m; i++) {
if (!vis[op[i].x]) {
int to, tmpx, tmpy, ans;
to = op[i].to;
tmpx = (to) ? op[i].y : op[i].x;
tmpy = (to) ? op[i].x : op[i].y;
ans = query(tmpx, 1, to);
printf("%d\n", (to) ? (x[tmpy] - x[ans]) : (y[tmpy] - y[ans]));
vis[op[i].x] = 1;
update(ans + 1, tmpy, 1, to^1, tmpx);
} else printf("0\n");
}
return 0;
}

D题：

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long LL;
#define N 200010

int n, m;
int x[N], y[N];

struct peg {
int x, id;

bool operator<(const peg ff) const {
return x < ff.x;
}
} tmp[N];

int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &x[i]);
tmp[i].x = x[i];
tmp[i].id = i;
}
sort(x + 1, x + n + 1);
sort(tmp + 1, tmp + n + 1);
for (int i = 1; i <= n; i++)
y[tmp[i].id] = i;
while (m--) {
int i, l, to = 1, cnt = 0, last = -1;
scanf("%d%d", &i, &l);
i = y[i];
while (true) {
if (cnt == 2) {
printf("%d\n", tmp[i].id);
break;
}
if (to) {
if (i + 1 > n || x[i + 1] - x[i] > l) {
cnt++;
to ^= 1;
continue;
}
cnt = 0;
int pos = x[i] + l;
int idx = upper_bound(x + 1, x + n + 1, pos) - x - 1;
if (idx == last) {
if (l / (x[idx] - x[i]) % 2) {
l %= x[idx] - x[i];
last = i;
i = idx;
to ^= 1;
} else {
l %= x[idx] - x[i];
}
} else {
l -= x[idx] - x[i];
last = i;
i = idx;
}
} else {
if (i - 1 < 1 || x[i] - x[i - 1] > l) {
cnt++;
to ^= 1;
continue;
}
cnt = 0;
int pos = x[i] - l;
int idx = lower_bound(x + 1, x + n + 1, pos) - x;
if (idx == last) {
if (l / (x[i] - x[idx]) % 2) {
l %= x[i] - x[idx];
last = i;
i = idx;
to ^= 1;
} else {
l %= x[i] - x[idx];
}
} else {
l -= x[i] - x[idx];
last = i;
i = idx;
}
}
to ^= 1;
}
}
return 0;
}

PS：

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：188248次
• 积分：4663
• 等级：
• 排名：第7254名
• 原创：285篇
• 转载：1篇
• 译文：0篇
• 评论：44条
文章分类
阅读排行
最新评论