QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624979#7752. The Only Way to the DestinationSatonCompile Error//C++204.1kb2024-10-09 17:02:562024-10-09 17:02:57

Judging History

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

  • [2024-10-09 17:02:57]
  • 评测
  • [2024-10-09 17:02:56]
  • 提交

answer

///by Saton.
#include<bits/stdc++.h>
#define PI acos(-1)
#define fi first
#define se second 
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define int long long
#define rep(i,a,b) for(int i = (a);i <= (b);i ++)
#define lep(i,a,b) for(int i = (a);i >= (b);i --)
#define FLUSH fflush(stdout)
using namespace std;
typedef pair<int,int> PII;
int n,m,k;

bool solve() {
    cin >> n >> m >> k;
    const int N = 2*k+1;
    vector<vector<PII>> w(N+1);
    rep(i,1,k) {
        int x1,x2,y;
        cin >> x1 >> x2 >> y;
        if(y<=N) w[y].push_back({x1,x2});
    }
    
    if(n==1) return true;
    if(m>N) return false;
    
    int edge = 0,node = 0;
    vector<PII> lst,cur;
    rep(i,1,m) {
        sort(all(w[i]));
        cur.clear();
        int l = 1;
        for(auto [x1,x2] : w[i]) {
            cur.push_back({l,x1-1});
            l = x2+1;
        }
        if(l<=n) cur.push_back({l,n});
        node += sz(cur);
        // cout << node << '\n';
        
        auto it = lst.begin();
        for(auto [curl,curr] : cur) {
            while(it!=lst.end() && it->fi<=curr) {
                auto [lstl,lstr] = *it ++;
                int l = max(curl,lstl),r = min(curr,lstr);
                if(l==r) edge ++;
                if(l<r) return false; 
            }
            if(it!=lst.end()) {
                it --;
            }
        }
        
        lst = cur;
    }
    
    // cout << node << " " << edge << '\n';
    return (edge==node-1);
} 

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    if(solve()) cout << "YES";
    else cout << "NO";
}  
/*   /\_/\
*   (= ._.)
*   / >  \>
*/#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second

bool chmin(auto &a, auto b) {  return b < a and (a = b, true); }
bool chmax(auto &a, auto b) {  return a < b and (a = b, true); }

using i64 = long long;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;

    const int C = 2*k+1;
    vector W(C + 1, vector<pair<int, int>>{});
    for (int i = 0; i < k; i++) {
        int x1, x2, y;
        cin >> x1 >> x2 >> y;
        if (y <= C) {
            W[y].push_back({x1, x2});
        }
    }

    if (n == 1) {
        cout << "YES\n";
        return;
    }

    if (m > C) {
        cout << "NO\n";
        return;
    }

    vector<pair<int, int>> lst;
    int edg = 0, nod = 0;
    for (int i = 1; i <= m; i++) {
        vector<pair<int, int>> cur;
        int l = 1;
        sort(all(W[i]));
        for (auto [a, b] : W[i]) {
            if (l < a) {
                cur.push_back({l, a - 1});
            }
            l = b + 1;
        }

        if (l <= n) {
            cur.push_back({l, n});
        }

        if (0){
            cerr << "l = " << l << '\n';
        cerr << " i = " << i << '\n';
        for (auto [a, b] : cur) {
            cerr << a << ' ' << b << '\n';
        }
        cerr << "==\n";
        }

        nod += cur.size();

        auto it = lst.begin();
        for (auto [a, b] : cur) {
            while (it != lst.end() and it->ff <= b) {
                auto [x, y] = *it++;
                x = max(x, a);
                y = min(y, b);
                if (x <= y) {
                    // cerr << " x = " << x << " y = " << y << "a = " << a << " b = " << b << '\n';
                    edg++;
                    if (y > x) {
                        cerr << "NO\n";
                        return;
                    }
                }
            }
            if (it != lst.begin()) {
                it--;
            }
        }

        lst = move(cur);
    }

    // cerr << "edg = " << edg << '\n';
    // cerr << "nod = " << nod << '\n';

    if (edg == nod - 1) {
        cerr << "YES\n";
    } else {
        cerr << "NO\n";
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

answer.code:75: warning: "all" redefined
   75 | #define all(v) (v).begin(), (v).end()
      | 
answer.code:7: note: this is the location of the previous definition
    7 | #define all(a) a.begin(), a.end()
      | 
answer.code:85:6: error: ambiguating new declaration of ‘void solve()’
   85 | void solve() {
      |      ^~~~~
answer.code:16:6: note: old declaration ‘bool solve()’
   16 | bool solve() {
      |      ^~~~~
answer.code:170:8: error: redefinition of ‘int main()’
  170 | signed main() {
      |        ^~~~
answer.code:63:8: note: ‘int main()’ previously defined here
   63 | signed main() {
      |        ^~~~