QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404776#6786. Let's ChatLZDYWA 1ms3500kbC++142.0kb2024-05-04 17:58:122024-05-04 17:58:14

Judging History

你现在查看的是最新测评结果

  • [2024-05-04 17:58:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3500kb
  • [2024-05-04 17:58:12]
  • 提交

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, b;
    int u, v;
    
    cin >> u >> v;
    a.push_back(make_pair(u, v));
    for(int i = 1; i < x; i++) {
        cin >> u >> v;
        
        if(abs(a[i - 1].second - u) <= 1) {
            a[i - 1].second = v;
        }else {
            a.push_back(make_pair(u, v));
        }
    }

    cin >> u >> v;
    b.push_back(make_pair(u, v));
    for(int i = 1; i < y; i++) {
        cin >> u >> v;

        if(abs(b[i - 1].second - u) <= 1) {
            b[i - 1].second = v;
        }else {
            b.push_back(make_pair(u, v));
        }
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int ans = 0;
    int i = 0, 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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3492kb

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: 0ms
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'