Submission #1224602

#TimeUsernameProblemLanguageResultExecution timeMemory
1224602JerInside information (BOI21_servers)C++20
10 / 100
538 ms2236 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 120005;
int n, k;
pair<int, int> r[MAXN];

void share(int a, int b){
    r[a] = r[b] = {min(r[a].first, r[b].first), max(r[a].second, r[b].second)};
}

int cnt(int i){
    int left = i, right = i;
    while (r[left].first <= i and r[left].second >= i) left--;
    while (r[right].first <= i and r[right].second >= i) right++;

    /*
    int l = 1, h = i, m = (l + h) / 2;

    while (l < h and m >= h and m <= l){
        m = (l + h) / 2;
        //cout << "L " << l << " " << h  << " " << m << "\n";
        if (r[m].first <= i and r[m].second >= i)
            left = m, h = m - 1;
        else
            l = m + 1;
    }

    l = i, h = n, m = (l + h) / 2;

    while (l < h and m <= h and m >= l){
        m = (l + h / 2);
        //cout  << "R " << l << " " << h << " " << m << "\n";
        if (r[m].first <= i and r[m].second >= i)
            right = m, l = m + 1;
        else
            h = m - 1;
    }

    //cout << left << " " << right << '\n';
    */
    return right - left - 1;
}

int main(){
    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; i++)
        r[i] = {i, i};

    char t;
    int a, b, c;
    int passed = 0;
    for (int z = 0; z < n + k - 1; z++)
    {
        scanf(" %c", &t);

        if (t == 'S')
        {
            scanf("%d%d", &a, &b);
            share(a, b);
        }

        if (t == 'Q')
        {
            scanf("%d%d", &a, &b);
            printf("%s\n", (b >= r[a].first and b <= r[a].second) ? "yes" : "no");
        }

        if (t == 'C')
        {
            scanf("%d", &c);
            printf("%d\n", cnt(c));
        }
    }

    return 0;
}

Compilation message (stderr)

servers.cpp: In function 'int main()':
servers.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
servers.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         scanf(" %c", &t);
      |         ~~~~~^~~~~~~~~~~
servers.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |             scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
servers.cpp:67:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |             scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
servers.cpp:73:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |             scanf("%d", &c);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...