QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#360335 | #6786. Let's Chat | Xiangmy# | AC ✓ | 1ms | 3680kb | C++20 | 2.8kb | 2024-03-21 17:33:51 | 2024-03-21 17:33:53 |
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;
typedef pair<LL, LL> PLL;
void solve() {
LL n, m, x, y; cin >> n >> m >> x >> y;
LL st = -1, ed = -1;
vector<PLL> 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<PLL> 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;
}
}
if (ed - st + 1 >= m) {
nowa.push_back({st, ed});
}
st = -1, ed = -1;
vector<PLL> 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<PLL> 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;
}
}
if (ed - st + 1 >= m) {
nowb.push_back({st, ed});
}
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(0ll, bs - bf + 1 - (m - 1));
j ++;
} else if (bs > as) {
ans += max(0ll, as - bf + 1 - (m - 1));
i ++;
} else {
i ++;
}
} else if (af > bf) {
if (as >= bs) {
ans += max(0ll, bs - af + 1 - (m - 1));
j ++;
} else if (bs > as) {
ans += max(0ll, 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;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
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: 0
Accepted
time: 1ms
memory: 3632kb
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:
119342838 35153801 144883974 82675908 33074404 41458373 4138220 69656059 71436009 110675349
result:
ok 10 lines