QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#360335#6786. Let's ChatXiangmy#AC ✓1ms3680kbC++202.8kb2024-03-21 17:33:512024-03-21 17:33:53

Judging History

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

  • [2024-03-21 17:33:53]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3680kb
  • [2024-03-21 17:33:51]
  • 提交

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,我给组数据试试?

详细

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