Submission #414905

#TimeUsernameProblemLanguageResultExecution timeMemory
414905Pro_ktmr스파이 (JOI13_spy)C++17
100 / 100
466 ms11392 KiB
#include"bits/stdc++.h" using namespace std; typedef long long ll; const ll MOD = (ll)(1e9+7); #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++) int N, M; int parA[2000], parB[2000]; vector<int> chiA[2000], chiB[2000]; int cnt = 0; int pre[2000], pos[2000]; void dfs(int n){ pre[n] = cnt; cnt++; rep(i, chiA[n].size()) dfs(chiA[n][i]); pos[n] = cnt; } void dfs2(int n, vector<int>* v){ v->pb(pre[n]); rep(i, chiB[n].size()) dfs2(chiB[n][i], v); } vector<pair<int, int>> query[2000]; int ans[2000] ={}; signed main(){ cin >> N >> M; rep(i, N){ int a, b; cin >> a >> b; parA[i] = a-1; if(a-1 >= 0) chiA[a-1].pb(i); parB[i] = b-1; if(b-1 >= 0) chiB[b-1].pb(i); } rep(i, N) if(parA[i] == -1) dfs(i); rep(i, M){ int a, b; cin >> a >> b; query[b-1].pb({ a-1,i }); } rep(i, N){ vector<int> v; dfs2(i, &v); sort(all(v)); vector<int> imos(v.size()+1, 0); rep(j, query[i].size()){ int lederA = query[i][j].first; int l = pre[lederA]; int r = pos[lederA]; imos[lower_bound(all(v), l)-v.begin()]++; imos[lower_bound(all(v), r)-v.begin()]--; } rep(j, v.size()){ if(j > 0) imos[j] += imos[j-1]; ans[v[j]] += imos[j]; } } rep(i, N) cout << ans[pre[i]] << endl; }

Compilation message (stderr)

spy.cpp: In function 'void dfs(int)':
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:19:2: note: in expansion of macro 'rep'
   19 |  rep(i, chiA[n].size()) dfs(chiA[n][i]);
      |  ^~~
spy.cpp: In function 'void dfs2(int, std::vector<int>*)':
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:25:2: note: in expansion of macro 'rep'
   25 |  rep(i, chiB[n].size()) dfs2(chiB[n][i], v);
      |  ^~~
spy.cpp: In function 'int main()':
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:33:2: note: in expansion of macro 'rep'
   33 |  rep(i, N){
      |  ^~~
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:41:2: note: in expansion of macro 'rep'
   41 |  rep(i, N)
      |  ^~~
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:43:2: note: in expansion of macro 'rep'
   43 |  rep(i, M){
      |  ^~~
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:48:2: note: in expansion of macro 'rep'
   48 |  rep(i, N){
      |  ^~~
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:53:3: note: in expansion of macro 'rep'
   53 |   rep(j, query[i].size()){
      |   ^~~
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:60:3: note: in expansion of macro 'rep'
   60 |   rep(j, v.size()){
      |   ^~~
spy.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
spy.cpp:65:2: note: in expansion of macro 'rep'
   65 |  rep(i, N) cout << ans[pre[i]] << endl;
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...