社区讨论
WA 75分求调
P4811 [COCI 2014/2015 #3] KAMIONI参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhj37ynb
- 此快照首次捕获于
- 2025/11/03 19:59 4 个月前
- 此快照最后确认于
- 2025/11/03 19:59 4 个月前
按照第一篇题解的思路写的
提交记录
CPP#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int k[100005];
vector<int> a[100005];
vector<long long> G[100005];
map<pair<int, int>, long long> mp;
int getpos(int fr, int t) {
// 第fr辆卡车第t秒的位置
int pos = upper_bound(G[fr].begin(), G[fr].end(), t) - G[fr].begin() - 1;
if (pos < 0) pos = 0;
// 向前走
if (a[fr][pos + 1] > a[fr][pos]) return a[fr][pos] + (t - G[fr][pos]);
// 向后走
return a[fr][pos] - (t - G[fr][pos]);
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> k[i];
ll now = 0;
// G 路程 a 位置
G[i].push_back(0);
for (int j = 1; j <= k[i]; j++) {
int x;
cin >> x;
a[i].push_back(x);
if (j != 1) {
now += abs(a[i][j - 1] - a[i][j - 2]);
G[i].push_back(now);
}
}
}
while (m--) {
int x, y;
cin >> x >> y;
// 记忆化
if (k[x] > k[y]) swap(x, y);
if (k[x] == k[y] && x > y) swap(x, y);
if (mp.count(make_pair(x, y))) {
cout << mp[make_pair(x, y)] << "\n";
continue;
}
int anscnt = 0;
for (int i = 0; i < k[x] - 1; i++) {
// i表示从第i个拐点到第i+1个拐点的路
if (G[x][i] >= G[y].back()) {
// 时间超出
break;
}
// 时间
long long x_1 = G[x][i];
long long x_2 = min(G[x][i + 1], G[y].back());
// 计算位置
ll xc = a[x][i];
ll yc = getpos(y, x_1);
ll xm = getpos(x, x_2);
ll ym = getpos(y, x_2);
// 相对位置改变 -> 相遇一次
anscnt += (xc > yc) ^ (xm > ym);
}
mp[make_pair(x, y)] = anscnt;
cout << anscnt << "\n";
}
return 0;
}
/*
*/
回复
共 0 条回复,欢迎继续交流。
正在加载回复...