QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632464#7752. The Only Way to the DestinationrealisationRE 5ms13556kbC++202.3kb2024-10-12 13:26:132024-10-12 13:26:17

Judging History

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

  • [2024-10-12 13:26:17]
  • 评测
  • 测评结果:RE
  • 用时:5ms
  • 内存:13556kb
  • [2024-10-12 13:26:13]
  • 提交

answer

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

#define endl '\n' 
#define int long long
const int N = 1e6+5, mod = 1e9+7;

vector<pair<int,int>> c[N], v[N];
map<array<int,3>,int> mp;
int fa[N];
int find(int x) {
    while(x!=fa[x]) {
        x = fa[x] = fa[fa[x]];
    } return x;
}

void solve(){

    int n, m, k;
    cin>>n>>m>>k;
    for(int i=1;i<=N-5;i++) fa[i] = i;
    for(int i=1;i<=k;i++) {
        int l, r, y;
        cin>>l>>r>>y;
        c[y].push_back({l,r});
    }
    if(m==1) {
        cout<<"YES"<<endl;
        return ;
    }
    if(m>=3*k) {
        cout<<"NO"<<endl;
        return ;
    }
    int cnt = 0;
    for(int i=1;i<=m;i++) {
        int l = 1;
        for(int j=0;j<c[i].size();j++) {
            if(l==n+1) break;
            int r = c[i][j].first-1;
            if(l<=r) {
                v[i].push_back({l,r});
                // cout<<l<<" "<<r<<" "<<i<<endl;
                mp[{l,r,i}] = ++cnt;
            }
            l = c[i][j].second+1;
        }    
        if(l<=n) {
            v[i].push_back({l,n});
            // cout<<l<<" "<<n<<" "<<i<<endl;
            mp[{l,n,i}] = ++cnt;
        }
    }
    auto ok = [&](int l, int r, int ll, int rr) {
        int len;
        int s = min(r, rr) - max(l, ll) + 1;
        len = max(0ll, s);
        return len>=2;
    };
    for(int i=2;i<=m;i++) {
        int len1 = v[i-1].size();
        int len2 = v[i].size();
        for(int j=0;j<len1;j++) {
            for(int z=0;z<len2;z++) {
                auto [l,r] = v[i-1][j];
                auto [ll,rr] = v[i][z];
                if(ok(l,r,ll,rr)) {
                    cout<<"NO"<<endl;
                    return ;
                }
                else if(max(l,ll)<=min(r,rr)) {
                    int x = mp[{l,r,i-1}];
                    int y = mp[{ll,rr,i}];
                    int fx = find(x);
                    int fy = find(y);
                    if(fx==fy) {
                        cout<<"NO"<<endl;
                        return ;
                    }
                    fa[fx] = fy;
                }
            }
        }
    }
    cout<<"YES"<<endl;

}

signed main() {

    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    // int T;
    // cin>>T;
    // while(T--)
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 13556kb

input:

5 3 2
2 5 1
1 4 3

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 4ms
memory: 12252kb

input:

5 3 1
2 4 2

output:

NO

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 4ms
memory: 13064kb

input:

2 4 2
2 2 1
1 1 4

output:

NO

result:

ok answer is NO

Test #4:

score: -100
Runtime Error

input:

409455775 596220461 69036
72554058 85866426 497212608
54242898 110165840 236869995
68671059 127632371 324336242
39386477 208393446 248270338
151972182 327931056 231832
36658944 75335495 293646122
29512382 138875677 205628469
149151850 327396301 590717922
114980184 165064700 323939243
1771834 7016377...

output:


result: