제출 #656030

#제출 시각아이디문제언어결과실행 시간메모리
656030ParsaSBitaro’s Party (JOI18_bitaro)C++17
7 / 100
1227 ms524288 KiB
// In the name of God #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef long long ll; const int N = 2e6 + 5, MOD = 1e9 + 7, SQ = N; vector<int> adj[N], vec[N], Q[N]; int n, m, q, T[N], prv[N]; unordered_set<int> st[N]; int cur, dis[N], ans[N]; vector<pair<int, int> > V[N]; void _merge(int v, int u) { vector<pair<int, int> > tmp; cur++; int l = 0, r = 0; while (l < V[v].size() && r < V[u].size() && tmp.size() < SQ) { while (l < V[v].size() && prv[V[v][l].se] == cur) l++; while (r < V[u].size() && prv[V[u][r].se] == cur) r++; if (l == V[v].size() || r == V[u].size()) break; pair<int, int> pl = V[v][l], pr = V[u][r]; pr.fi++; if (pl >= pr) { tmp.pb(pl); prv[pl.se] = cur; l++; } else { tmp.pb(pr); prv[pr.se] = cur; r++; } } while (tmp.size() < SQ && l < V[v].size()) { while (l < V[v].size() && prv[V[v][l].se] == cur) l++; if (l == V[v].size()) break; tmp.pb(V[v][l]); prv[V[v][l].se] = cur; l++; } while (tmp.size() < SQ && r < V[u].size()) { while (r < V[u].size() && prv[V[u][r].se] == cur) { r++; } if (r == V[u].size()) break; tmp.pb(V[u][r]); tmp.back().fi++; prv[V[u][r].se] = cur; r++; } swap(V[v], tmp); } void brute_force(int r) { for (int j = 1; j <= r; j++) dis[j] = -1; dis[r] = 0; for (int i = r; i > 1; i--) { for (auto j : adj[i]) { dis[j] = max(dis[j], dis[i] + 1); } } } void solve() { cin >> n >> m >> q; for (int i = 0; i < m; i++) { int s, e; cin >> s >> e; adj[e].pb(s); } for (int i = 0; i < q; i++) { cin >> T[i]; int y; cin >> y; for (int j = 0; j < y; j++) { int x; cin >> x; if (x <= T[i]) st[i].insert(x); } Q[T[i]].pb(i); } for (int i = 1; i <= n; i++) { V[i].pb(mp(0, i)); for (auto u : adj[i]) { _merge(i, u); } /*cout << i << " : "; for (auto x : V[i]) cout << x.fi << ' ' << x.se << endl;*/ bool ok = false; vector<pair<int, int> > tmp; for (auto j : Q[i]) { if (st[j].size() >= SQ) { if (!ok) { brute_force(i); for (int k = 1; k <= i; k++) tmp.pb(mp(dis[k], k)); sort(tmp.begin(), tmp.end(), greater<pair<int, int> >()); } ok = true; int inx = 0; while (inx < tmp.size() && st[j].find(tmp[inx].se) != st[j].end()) { inx++; } ans[j] = (inx == tmp.size() ? -1 : tmp[inx].fi); } else { int inx = 0; while (inx < V[i].size() && st[j].find(V[i][inx].se) != st[j].end()) inx++; ans[j] = (inx == V[i].size() ? -1 : V[i][inx].fi); } } /*if (ok) { vector<pair<int, int> > tmp; brute_force(i); for (int j = 1; j <= i; j++) { tmp.pb(mp(dis[j], j)); } sort(tmp.begin(), tmp.end(), greater<pair<int, int> >()); for (auto j : Q[i]) { } }*/ } for (int i = 0; i < q; i++) cout << ans[i] << '\n'; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); return 0; }

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

bitaro.cpp: In function 'void _merge(int, int)':
bitaro.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     while (l < V[v].size() && r < V[u].size() && tmp.size() < SQ) {
      |            ~~^~~~~~~~~~~~~
bitaro.cpp:21:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     while (l < V[v].size() && r < V[u].size() && tmp.size() < SQ) {
      |                               ~~^~~~~~~~~~~~~
bitaro.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         while (l < V[v].size() && prv[V[v][l].se] == cur)
      |                ~~^~~~~~~~~~~~~
bitaro.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while (r < V[u].size() && prv[V[u][r].se] == cur)
      |                ~~^~~~~~~~~~~~~
bitaro.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (l == V[v].size() || r == V[u].size())
      |             ~~^~~~~~~~~~~~~~
bitaro.cpp:26:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (l == V[v].size() || r == V[u].size())
      |                                 ~~^~~~~~~~~~~~~~
bitaro.cpp:41:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     while (tmp.size() < SQ && l < V[v].size()) {
      |                               ~~^~~~~~~~~~~~~
bitaro.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         while (l < V[v].size() && prv[V[v][l].se] == cur)
      |                ~~^~~~~~~~~~~~~
bitaro.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if (l == V[v].size())
      |             ~~^~~~~~~~~~~~~~
bitaro.cpp:50:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     while (tmp.size() < SQ && r < V[u].size()) {
      |                               ~~^~~~~~~~~~~~~
bitaro.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         while (r < V[u].size() && prv[V[u][r].se] == cur) {
      |                ~~^~~~~~~~~~~~~
bitaro.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if (r == V[u].size())
      |             ~~^~~~~~~~~~~~~~
bitaro.cpp: In function 'void solve()':
bitaro.cpp:111:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |                 while (inx < tmp.size() && st[j].find(tmp[inx].se) != st[j].end()) {
      |                        ~~~~^~~~~~~~~~~~
bitaro.cpp:114:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |                 ans[j] = (inx == tmp.size() ? -1 : tmp[inx].fi);
      |                           ~~~~^~~~~~~~~~~~~
bitaro.cpp:118:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |                 while (inx < V[i].size() && st[j].find(V[i][inx].se) != st[j].end())
      |                        ~~~~^~~~~~~~~~~~~
bitaro.cpp:120:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |                 ans[j] = (inx == V[i].size() ? -1 : V[i][inx].fi);
      |                           ~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...