Submission #598404

#TimeUsernameProblemLanguageResultExecution timeMemory
598404gagik_2007Inside information (BOI21_servers)C++17
10 / 100
408 ms58260 KiB
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;

string findSum(string str1, string str2)
{
    if (str1.length() > str2.length())
        swap(str1, str2);
    string str = "";
    int n1 = str1.length(), n2 = str2.length();
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());
    int carry = 0;
    for (int i = 0; i < n1; i++)
    {
        int sum = ((str1[i] - '0') + (str2[i] - '0') + carry);
        str.push_back(sum % 10 + '0');
        carry = sum / 10;
    }
    for (int i = n1; i < n2; i++)
    {
        int sum = ((str2[i] - '0') + carry);
        str.push_back(sum % 10 + '0');
        carry = sum / 10;
    }
    if (carry)
        str.push_back(carry + '0');
    reverse(str.begin(), str.end());
    return str;
}
bool isSmaller(string str1, string str2)
{
    int n1 = str1.length(), n2 = str2.length();
    if (n1 < n2)
        return true;
    if (n2 < n1)
        return false;
    for (int i = 0; i < n1; i++)
        if (str1[i] < str2[i])
            return true;
        else if (str1[i] > str2[i])
            return false;
    return false;
}
string findDiff(string str1, string str2)
{
    if (isSmaller(str1, str2))
        swap(str1, str2);
    string str = "";
    int n1 = str1.length(), n2 = str2.length();
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());
    int carry = 0;
    for (int i = 0; i < n2; i++) {
        int sub
            = ((str1[i] - '0') - (str2[i] - '0') - carry);
        if (sub < 0) {
            sub = sub + 10;
            carry = 1;
        }
        else
            carry = 0;
        str.push_back(sub + '0');
    }
    for (int i = n2; i < n1; i++) {
        int sub = ((str1[i] - '0') - carry);
        if (sub < 0) {
            sub = sub + 10;
            carry = 1;
        }
        else
            carry = 0;
        str.push_back(sub + '0');
    }
    reverse(str.begin(), str.end());
    return str;
}

typedef long long ll;
typedef long double ld;
typedef ll itn;

#define ff first
#define ss second

ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 32768;
const ll N = 100007;
ll n, m, k;
ll t[200007];
bool d[4007][4007];
ll c[4007];
vector<int>g[4007];
ll timer = 1;

int main() {
    cin >> n >> k;
    if (n <= 4000) {
        for (int i = 1; i <= n; i++) {
            d[i][i] = true;
            c[i] = 1;
            g[i].push_back(i);
        }
        for (int i = 0; i < n + k - 1; i++) {
            char typ;
            cin >> typ;
            if (typ == 'S') {
                ll x, y;
                cin >> x >> y;
                vector<int>v;
                for (int vl : g[x]) {
                    d[y][vl] = true;
                    c[vl]++;
                    v.push_back(vl);
                }
                for (int vl : g[y]) {
                    d[x][vl] = true;
                    c[vl]++;
                    v.push_back(vl);
                }
                g[x].clear();
                g[y].clear();
                for (int i = 0; i < v.size(); i++) {
                    g[x].push_back(v[i]);
                    g[y].push_back(v[i]);
                }
            }
            else if (typ == 'Q') {
                ll x, y;
                cin >> x >> y;
                cout << (d[x][y] ? "yes" : "no") << endl;
            }
            else {
                ll x;
                cin >> x;
                cout << c[x] << endl;
            }
        }
    }
    else {
        for (int i = 0; i < n + k - 1; i++) {
            char typ;
            cin >> typ;
            if (typ == 'S') {
                ll x, y;
                cin >> x >> y;
                t[x + y - 1] = timer++;
            }
            else if (typ == 'Q') {
                ll x, y;
                cin >> x >> y;
                if (x == y)cout << "yes\n";
                else if (x == 1) {
                    cout << (t[y] ? "yes" : "no") << endl;
                }
                else if (y == 1) {
                    cout << (t[x] ? "yes" : "no") << endl;
                }
                else if (!t[x] || !t[y] || (t[y] >= t[x])) {
                    cout << "no\n";
                }
                else cout << "yes\n";
            }
            else {
                ll x;
                cin >> x;
                if (x != 1 && !t[x]) {
                    cout << 1 << endl;
                }
                else {
                    cout << timer - t[x] + 1 - (x == 1) << endl;
                }
            }
        }
    }
}

/*
6 13
C 1
S 1 2
S 1 3
C 3
C 4
S 1 4
Q 5 1
C 1
S 1 5
S 1 6
Q 5 1
Q 1 5
Q 4 5
Q 6 5
Q 5 5
C 2
C 5
C 6
*/

Compilation message (stderr)

servers.cpp: In function 'int main()':
servers.cpp:140:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |                 for (int i = 0; i < v.size(); i++) {
      |                                 ~~^~~~~~~~~~
#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...