제출 #1118716

#제출 시각아이디문제언어결과실행 시간메모리
1118716vjudge1Klasika (COCI20_klasika)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

#define TASK ""
#define REP(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, a, b) for(auto i = a; i <= b; i++)
#define FORD(i, a, b) for(auto i = a; i >= b; i--)
template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; }
template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; }

mt19937 rng(time(0));

const int N = (int)2e5 + 7;
int q;
vector<int> adj[N];
int n = 1;
int f[N];

void Read()
{
    cin >> q;
}

namespace Subtask2
{
    bool Check()
    {
        return q <= 2000;
    }

    string type;
    int a, b;
    int ans = 0;

    void DFS(int u)
    {
        maximize(ans, f[a] ^ f[u]);
        for(int v : adj[u])
        {
            DFS(v);
        }
    }


    void Solve()
    {
        REP(i, q)
        {
            cin >> type >> a >> b;
            if(type[0] == 'A')
            {
                ++n;
                adj[a].push_back(n);
                f[n] = f[a] ^ b;
            }
            else
            {
                ans = 0;
                DFS(b);
                cout << ans << '\n';
            }
        }
    }
}

namespace Subtask3
{
    #define int long long
    int child[30 * N][2], sz = 0;
//    bool isEnd[100];

    string type;
    int a, b;

    void Ins(int mask)
    {
        int u = 0;
        FORD(i, 31, 0)
        {
            int val = mask >> i & 1;
            if(!child[u][val])
            {
                child[u][val] = ++sz;
                u = sz;
            }
            else
                u = child[u][val];
        }
    }

    int Ask(int mask)
    {
        int u = 0, res = 0;
        FORD(i, 31, 0)
        {
            int val = mask >> i & 1;
            val ^= 1;
            if(child[u][val])
            {
                u = child[u][val];
                res += (1 << i);
            }
            else
            {
                u = child[u][val ^ 1];
            }
        }
        return res;
    }

    void Solve()
    {
        REP(i, q)
        {
            cin >> type >> a >> b;
            if(type[0] == 'A')
            {
                ++n;
                f[n] = f[a] ^ b;
                Ins(f[n]);
            }
            else
            {
                cout << Ask(f[a]) << '\n';
            }
        }
    }
}

void Solve()
{
    if(Subtask2::Check()) return Subtask2::Solve();
    return Subtask3::Solve();
}

signed main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
    if(fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }

    Read();
    Solve();

    return 0;
}

/*
5
Add 1 8
Add 2 7
Add 1 4
Add 4 3
Query 3 1
*/
#include <bits/stdc++.h>

using namespace std;

#define TASK ""
#define REP(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, a, b) for(auto i = a; i <= b; i++)
#define FORD(i, a, b) for(auto i = a; i >= b; i--)
template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; }
template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; }

mt19937 rng(time(0));

const int N = (int)2e5 + 7;
int q;
vector<int> adj[N];
int n = 1;
int f[N];

void Read()
{
    cin >> q;
}

namespace Subtask2
{
    bool Check()
    {
        return q <= 2000;
    }

    string type;
    int a, b;
    int ans = 0;

    void DFS(int u)
    {
        maximize(ans, f[a] ^ f[u]);
        for(int v : adj[u])
        {
            DFS(v);
        }
    }


    void Solve()
    {
        REP(i, q)
        {
            cin >> type >> a >> b;
            if(type[0] == 'A')
            {
                ++n;
                adj[a].push_back(n);
                f[n] = f[a] ^ b;
            }
            else
            {
                ans = 0;
                DFS(b);
                cout << ans << '\n';
            }
        }
    }
}

namespace Subtask3
{
    #define int long long
    int child[30 * N][2], sz = 0;
//    bool isEnd[100];

    string type;
    int a, b;

    void Ins(int mask)
    {
        int u = 0;
        FORD(i, 31, 0)
        {
            int val = mask >> i & 1;
            if(!child[u][val])
            {
                child[u][val] = ++sz;
                u = sz;
            }
            else
                u = child[u][val];
        }
    }

    int Ask(int mask)
    {
        int u = 0, res = 0;
        FORD(i, 31, 0)
        {
            int val = mask >> i & 1;
            val ^= 1;
            if(child[u][val])
            {
                u = child[u][val];
                res += (1 << i);
            }
            else
            {
                u = child[u][val ^ 1];
            }
        }
        return res;
    }

    void Solve()
    {
        REP(i, q)
        {
            cin >> type >> a >> b;
            if(type[0] == 'A')
            {
                ++n;
                f[n] = f[a] ^ b;
                Ins(f[n]);
            }
            else
            {
                cout << Ask(f[a]) << '\n';
            }
        }
    }
}

void Solve()
{
    if(Subtask2::Check()) return Subtask2::Solve();
    return Subtask3::Solve();
}

signed main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
    if(fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }

    Read();
    Solve();

    return 0;
}

/*
5
Add 1 8
Add 2 7
Add 1 4
Add 4 3
Query 3 1
*/

컴파일 시 표준 에러 (stderr) 메시지

klasika.cpp:171:24: error: redefinition of 'template<class T> bool maximize(T&, T)'
  171 | template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; }
      |                        ^~~~~~~~
klasika.cpp:9:24: note: 'template<class T> bool maximize(T&, T)' previously declared here
    9 | template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; }
      |                        ^~~~~~~~
klasika.cpp:172:24: error: redefinition of 'template<class T> bool minimize(T&, T)'
  172 | template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; }
      |                        ^~~~~~~~
klasika.cpp:10:24: note: 'template<class T> bool minimize(T&, T)' previously declared here
   10 | template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; }
      |                        ^~~~~~~~
klasika.cpp:174:9: error: redefinition of 'std::mt19937 rng'
  174 | mt19937 rng(time(0));
      |         ^~~
klasika.cpp:12:9: note: 'std::mt19937 rng' previously declared here
   12 | mt19937 rng(time(0));
      |         ^~~
klasika.cpp:176:11: error: conflicting declaration 'const long long int N'
  176 | const int N = (int)2e5 + 7;
      |           ^
klasika.cpp:14:11: note: previous declaration as 'const int N'
   14 | const int N = (int)2e5 + 7;
      |           ^
klasika.cpp:177:5: error: conflicting declaration 'long long int q'
  177 | int q;
      |     ^
klasika.cpp:15:5: note: previous declaration as 'int q'
   15 | int q;
      |     ^
klasika.cpp:178:13: error: conflicting declaration 'std::vector<long long int> adj [200007]'
  178 | vector<int> adj[N];
      |             ^~~
klasika.cpp:16:13: note: previous declaration as 'std::vector<int> adj [200007]'
   16 | vector<int> adj[N];
      |             ^~~
klasika.cpp:179:5: error: conflicting declaration 'long long int n'
  179 | int n = 1;
      |     ^
klasika.cpp:17:5: note: previous declaration as 'int n'
   17 | int n = 1;
      |     ^
klasika.cpp:180:5: error: conflicting declaration 'long long int f [200007]'
  180 | int f[N];
      |     ^
klasika.cpp:18:5: note: previous declaration as 'int f [200007]'
   18 | int f[N];
      |     ^
klasika.cpp:182:6: error: redefinition of 'void Read()'
  182 | void Read()
      |      ^~~~
klasika.cpp:20:6: note: 'void Read()' previously defined here
   20 | void Read()
      |      ^~~~
klasika.cpp:189:10: error: redefinition of 'bool Subtask2::Check()'
  189 |     bool Check()
      |          ^~~~~
klasika.cpp:27:10: note: 'bool Subtask2::Check()' previously defined here
   27 |     bool Check()
      |          ^~~~~
klasika.cpp:194:12: error: redefinition of 'std::string Subtask2::type'
  194 |     string type;
      |            ^~~~
klasika.cpp:32:12: note: 'std::string Subtask2::type' previously declared here
   32 |     string type;
      |            ^~~~
klasika.cpp:195:9: error: conflicting declaration 'long long int Subtask2::a'
  195 |     int a, b;
      |         ^
klasika.cpp:33:9: note: previous declaration as 'int Subtask2::a'
   33 |     int a, b;
      |         ^
klasika.cpp:195:12: error: conflicting declaration 'long long int Subtask2::b'
  195 |     int a, b;
      |            ^
klasika.cpp:33:12: note: previous declaration as 'int Subtask2::b'
   33 |     int a, b;
      |            ^
klasika.cpp:196:9: error: conflicting declaration 'long long int Subtask2::ans'
  196 |     int ans = 0;
      |         ^~~
klasika.cpp:34:9: note: previous declaration as 'int Subtask2::ans'
   34 |     int ans = 0;
      |         ^~~
klasika.cpp:208:10: error: redefinition of 'void Subtask2::Solve()'
  208 |     void Solve()
      |          ^~~~~
klasika.cpp:46:10: note: 'void Subtask2::Solve()' previously defined here
   46 |     void Solve()
      |          ^~~~~
klasika.cpp:232:9: error: redefinition of 'long long int Subtask3::child [6000210][2]'
  232 |     int child[30 * N][2], sz = 0;
      |         ^~~~~
klasika.cpp:70:9: note: 'long long int Subtask3::child [6000210][2]' previously declared here
   70 |     int child[30 * N][2], sz = 0;
      |         ^~~~~
klasika.cpp:232:27: error: redefinition of 'long long int Subtask3::sz'
  232 |     int child[30 * N][2], sz = 0;
      |                           ^~
klasika.cpp:70:27: note: 'long long int Subtask3::sz' previously defined here
   70 |     int child[30 * N][2], sz = 0;
      |                           ^~
klasika.cpp:235:12: error: redefinition of 'std::string Subtask3::type'
  235 |     string type;
      |            ^~~~
klasika.cpp:73:12: note: 'std::string Subtask3::type' previously declared here
   73 |     string type;
      |            ^~~~
klasika.cpp:236:9: error: redefinition of 'long long int Subtask3::a'
  236 |     int a, b;
      |         ^
klasika.cpp:74:9: note: 'long long int Subtask3::a' previously declared here
   74 |     int a, b;
      |         ^
klasika.cpp:236:12: error: redefinition of 'long long int Subtask3::b'
  236 |     int a, b;
      |            ^
klasika.cpp:74:12: note: 'long long int Subtask3::b' previously declared here
   74 |     int a, b;
      |            ^
klasika.cpp:238:10: error: redefinition of 'void Subtask3::Ins(long long int)'
  238 |     void Ins(int mask)
      |          ^~~
klasika.cpp:76:10: note: 'void Subtask3::Ins(long long int)' previously defined here
   76 |     void Ins(int mask)
      |          ^~~
klasika.cpp:254:9: error: redefinition of 'long long int Subtask3::Ask(long long int)'
  254 |     int Ask(int mask)
      |         ^~~
klasika.cpp:92:9: note: 'long long int Subtask3::Ask(long long int)' previously defined here
   92 |     int Ask(int mask)
      |         ^~~
klasika.cpp:274:10: error: redefinition of 'void Subtask3::Solve()'
  274 |     void Solve()
      |          ^~~~~
klasika.cpp:112:10: note: 'void Subtask3::Solve()' previously defined here
  112 |     void Solve()
      |          ^~~~~
klasika.cpp:293:6: error: redefinition of 'void Solve()'
  293 | void Solve()
      |      ^~~~~
klasika.cpp:131:6: note: 'void Solve()' previously defined here
  131 | void Solve()
      |      ^~~~~
klasika.cpp:299:8: error: redefinition of 'int main()'
  299 | signed main(void)
      |        ^~~~
klasika.cpp:137:8: note: 'int main()' previously defined here
  137 | signed main(void)
      |        ^~~~
klasika.cpp: In function 'int main()':
klasika.cpp:142:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  142 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp: In function 'int main()':
klasika.cpp:304:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  304 |     if(fopen("TASK.INP", "r")) freopen("TASK.INP", "r", stdin);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:307:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  307 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:308:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  308 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~