QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661684#7752. The Only Way to the Destinationzrj66WA 0ms3844kbC++233.4kb2024-10-20 17:32:462024-10-20 17:32:47

Judging History

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

  • [2024-10-20 17:32:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-10-20 17:32:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define x first 
#define y second

using i128 = __int128; 
using PII = pair<int, int>;

const int N = 300010;
int n, m, K, idx, rt;

struct Node{
    int l, r;
    int sum, add;
}tr[N * 100];

void push_up(int u){
    tr[u].sum = tr[tr[u].l].sum + tr[tr[u].r].sum;
}

void push_down(int u, int l, int r){
    if(tr[u].add){
        if(!tr[u].l) tr[u].l = ++ idx;
        if(!tr[u].r) tr[u].r = ++ idx;
        Node &root = tr[u], &left = tr[tr[u].l], &right = tr[tr[u].r];
        int mid = l + r >> 1;
        left.add += root.add, left.sum = root.add * (mid - l + 1);
        right.add += root.add, right.sum = root.add * (r - mid);
        root.add = 0;
    }
}

void modify(int &u, int l, int r, int pl, int pr, int x){
    if(!u) u = ++ idx;
    if(l >= pl && r <= pr){
        tr[u].sum += x * (r - l + 1);
        tr[u].add += x;
        return;
    }
    int mid = l + r >> 1;
    push_down(u, l, r);
    if(pl <= mid) modify(tr[u].l, l, mid, pl, pr, x);
    if(pr > mid) modify(tr[u].r, mid + 1, r, pl, pr, x);
    push_up(u);
}

int query(int u, int l, int r, int pl, int pr){
    if(!u) return 0; 
    if(l >= pl && r <= pr){
        return tr[u].sum;
    }
    int mid = l + r >> 1;
    push_down(u, l, r);
    int ans = 0;
    if(pl <= mid) ans = query(tr[u].l, l, mid, pl, pr);
    if(pr > mid) ans += query(tr[u].r, mid + 1, r, pl, pr);
    return ans;
}

void solve(){
    
    cin >> n >> m >> K;
    m = min(m, N);
    vector<vector<PII> > stk(min(m + 1, N));

    for(int i = 1; i <= K; i ++){
        int x1, x2, y;
        cin >> x1 >> x2 >> y;
        if(y <= m) stk[y].push_back({x1, x2});
    }
    
    for(int i = 1; i <= m; i ++){
        if(i == 1){
            for(auto [x1, x2] : stk[i]){
                modify(rt, 1, 1e9, x1, x2, 1);
            }
            
        }
        else{
            int last = 1;
            sort(stk[i].begin(), stk[i].end());
            // cout << stk[i].size() << "\n";
            for(auto [x1, x2] : stk[i]){
                if(abs(x1 - last) > 1){
                    int t = query(rt, 1, 1e9, last, x1 - 1);
                    int len = x1 - last;
                    if(abs(t - len) > 1){
                        cout << "NO\n";
                        return;
                    }
                    
                }
                modify(rt, 1, 1e9, x1, x2, 1);
                last = x2 + 1;
            }
            
            if(last != n){
                int t = query(rt, 1, 1e9, last, n);
                    // if(i == 3){
                    //     cout << t << " " << last << " " << n << "\n";
                    // }
                int len = n - last + 1;
                if(abs(t - len) > 1){
                    cout << "NO\n";
                    return;
                }
            }
            
            for(auto [x1, x2] : stk[i - 2]){
                modify(rt, 1, 1e9, x1, x2, -1);
            }
        }
    }

    cout << "YES\n";

    
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    // cin >> _; 
    while(_--){
        solve();
    }
}

/*
3 3 3 
1 1 1
3 3 1
2 2 3

6 5 5 
1 2 5
1 6 2
5 6 2
4 5 3
4 6 5

7 4 6
3 6 1
2 2 2
7 7 2
1 1 3
2 2 3
7 7 3

4 6 6
4 4 1
1 2 2
4 4 3
1 2 4
4 4 5
1 2 6

*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

5 3 2
2 5 1
1 4 3

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

5 3 1
2 4 2

output:

NO

result:

ok answer is NO

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3844kb

input:

2 4 2
2 2 1
1 1 4

output:

YES

result:

wrong answer expected NO, found YES