QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404789 | #6786. Let's Chat | LZDY | WA | 1ms | 3508kb | C++14 | 2.1kb | 2024-05-04 18:36:27 | 2024-05-04 18:36:29 |
Judging History
answer
#include<vector>
#include<iostream>
#include<algorithm>
#define int long long
#define endl "\n"
using namespace std;
const int maxn = (int) 1e6 + 10;
void solve() {
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<pair<int, int>> a(x), b(y);
int u, v;
for(int i = 0; i < x; i++) {
cin >> u >> v;
a[i] = make_pair(u, v);
}
for(int i = 0; i < y; i++) {
cin >> u >> v;
b[i] = make_pair(u, v);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int i = 0;
for(int j = 1; j < x; j++) {
if(a[j].first - a[i].second <= 1) {
a[i].second = a[j].second;
}else {
a[++i] = a[j];
}
}
a.resize(i + 1);
i = 0;
for(int j = 1; j < y; j++) {
if(b[j].first - b[i].second <= 1){
b[i].second = b[j].second;
}else {
b[++i] = b[j];
}
}
b.resize(i + 1);
int ans = 0;
i = 0;
int j = 0;
while(i < a.size() && j < b.size()) {
pair<int, int> aa, bb;
aa = a[i]; bb = b[j];
if(aa.second <= bb.first) {
i++;
continue;
}
if(aa.first >= bb.second) {
j++;
continue;
}
if(aa.first <= bb.first && aa.second >= bb.second) {
ans += bb.second - bb.first + 1 - m + 1;
}else if(aa.first >= bb.first && aa.second <= bb.second) {
ans += aa.second - aa.first + 1 - m + 1;
}else if(aa.first <= bb.first && aa.second <= bb.second){
ans += aa.second - bb.first + 1 - m + 1;
}else if(aa.first >= bb.first && aa.second >= bb.second) {
ans += bb.second - aa.first + 1 - m + 1;
}
if(aa.second < bb.second) {
i ++;
}else{
j ++;
}
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc;
cin >> tc;
while(tc--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
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: 3500kb
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:
54626580 -3092172 83040465 52911773 17482642 26237585 2252066 37297449 39064335 92353307
result:
wrong answer 1st lines differ - expected: '119342838', found: '54626580'