QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360292 | #6786. Let's Chat | Xiangmy# | WA | 1ms | 3588kb | C++20 | 2.7kb | 2024-03-21 17:02:12 | 2024-03-21 17:02:15 |
Judging History
answer
/*
* Author: Xiangmy
* Created: 2024-03-21 16:28
* Problem:
* Description:
*/
// #pragma GCC optimize(2)
// #pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << ' '
// #define x first
// #define y second
typedef long long LL;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
void solve() {
int n, m, x, y; cin >> n >> m >> x >> y;
int st = -1, ed = -1;
vector<PII> atob;
for (int i = 1; i <= x; ++ i) {
int a, b; cin >> a >> b;
atob.push_back({a, b});
}
sort(atob.begin(), atob.end());
vector<PII> nowa;
for (int i = 0; i < x; ++ i) {
if (atob[i].first <= ed + 1) {
ed = max(ed, atob[i].second);
} else {
if (ed - st + 1 >= m) {
nowa.push_back({st, ed});
}
st = atob[i].first, ed = atob[i].second;
}
}
st = -1, ed = -1;
vector<PII> btoa;
for (int i = 1; i <= y; ++ i) {
int a, b; cin >> a >> b;
btoa.push_back({a, b});
}
sort(btoa.begin(), btoa.end());
vector<PII> nowb;
for (int i = 0; i < y; ++ i) {
if (btoa[i].first <= ed + 1) {
ed = max(ed, btoa[i].second);
} else {
if (ed - st + 1 >= m) {
nowb.push_back({st, ed});
}
st = btoa[i].first, ed = btoa[i].second;
}
}
LL ans = 0;
for (int i = 0, j = 0; i < nowa.size() && j < nowb.size(); ) {
int af = nowa[i].first, as = nowa[i].second;
int bf = nowb[j].first, bs = nowb[j].second;
if (af <= bf) {
if (as >= bs) {
ans += max(0, bs - bf + 1 - (m - 1));
j ++;
} else if (bs > as) {
ans += max(0, as - bf + 1 - (m - 1));
i ++;
} else {
i ++;
}
} else if (af > bf) {
if (as >= bs) {
ans += max(0, bs - af + 1 - (m - 1));
j ++;
} else if (bs > as) {
ans += max(0, as - af + 1 - (m - 1));
i ++;
} else {
j ++;
}
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); // 交互题不用
cout.tie(0);
// cout << fixed << setprecision(6);
// cout << setw(4) << setfill('0');
// init();
int T = 1;
cin >> T;
while (T -- ) {
// cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
2 10 3 3 2 1 3 5 8 10 10 1 8 10 10 5 3 1 1 1 2 4 5
output:
3 0
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3548kb
input:
10 978378582 3619603 47 74 479986 5351489 5420308 7962369 11344514 15240567 28052230 34309090 69930493 71370103 96064381 113030999 131487830 167306026 201120250 210905551 215581108 218116928 239370726 250969994 251488779 259451325 264979602 268998475 277209414 278821999 294684099 297838279 300870315...
output:
111023529 28676471 144883974 76541909 33074404 34389356 4078464 69642797 71436009 87455214
result:
wrong answer 1st lines differ - expected: '119342838', found: '111023529'