Submission #430916

# Submission time Handle Problem Language Result Execution time Memory
430916 2021-06-17T07:58:23 Z juggernaut Regions (IOI09_regions) C++17
30 / 100
1234 ms 44360 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
int n,r,q;
int cnt[25005];
int reg[200005];
vector<int>g[200005];
int precalc[505][505];
int tmp[505];
void dfs(int v){
    for(int i=1;i<=500;i++)precalc[i][reg[v]]+=tmp[i];
    tmp[reg[v]]++;
    for(int to:g[v])dfs(to);
    tmp[reg[v]]--;
}
int main(){
    scanf("%d%d%d",&n,&r,&q);
    scanf("%d",&reg[1]);
    cnt[reg[1]]++;
    for(int i=2;i<=n;i++){
        int par;
        scanf("%d%d",&par,&reg[i]);
        cnt[reg[i]]++;
        g[par].push_back(i);
    }
    dfs(1);
    while(q--){
        int x,y;
        scanf("%d%d",&x,&y);
        printf("%d\n",precalc[x][y]);
        fflush(stdout);
    }
}

Compilation message

regions.cpp: In function 'void usaco(std::string)':
regions.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp: In function 'int main()':
regions.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d%d",&n,&r,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
regions.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d",&reg[1]);
      |     ~~~~~^~~~~~~~~~~~~~
regions.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d%d",&par,&reg[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
regions.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5960 KB Output is correct
2 Correct 4 ms 5960 KB Output is correct
3 Correct 5 ms 5960 KB Output is correct
4 Correct 9 ms 5960 KB Output is correct
5 Correct 8 ms 5960 KB Output is correct
6 Correct 24 ms 5960 KB Output is correct
7 Correct 29 ms 6012 KB Output is correct
8 Correct 33 ms 5960 KB Output is correct
9 Correct 59 ms 6344 KB Output is correct
10 Correct 87 ms 6300 KB Output is correct
11 Correct 118 ms 6444 KB Output is correct
12 Correct 81 ms 6892 KB Output is correct
13 Correct 139 ms 6432 KB Output is correct
14 Correct 167 ms 6900 KB Output is correct
15 Correct 201 ms 9232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 634 ms 9136 KB Output is correct
2 Correct 695 ms 7932 KB Output is correct
3 Correct 1234 ms 10696 KB Output is correct
4 Runtime error 45 ms 13772 KB Execution killed with signal 11
5 Runtime error 49 ms 16960 KB Execution killed with signal 11
6 Runtime error 29 ms 15068 KB Execution killed with signal 11
7 Runtime error 34 ms 16228 KB Execution killed with signal 11
8 Runtime error 59 ms 20544 KB Execution killed with signal 11
9 Runtime error 56 ms 22000 KB Execution killed with signal 11
10 Runtime error 112 ms 27444 KB Execution killed with signal 11
11 Runtime error 255 ms 21184 KB Execution killed with signal 11
12 Runtime error 84 ms 25392 KB Execution killed with signal 11
13 Runtime error 74 ms 24504 KB Execution killed with signal 11
14 Runtime error 276 ms 24876 KB Execution killed with signal 11
15 Runtime error 93 ms 26304 KB Execution killed with signal 11
16 Runtime error 244 ms 44360 KB Execution killed with signal 11
17 Runtime error 71 ms 26300 KB Execution killed with signal 11