제출 #549663

#제출 시각아이디문제언어결과실행 시간메모리
549663Jarif_RahmanToll (BOI17_toll)C++17
100 / 100
500 ms32200 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e17; int k; struct node{ bool dummy; vector<vector<ll>> A, B; node(){ dummy = 1; A.assign(k, vector<ll>(k, 0)); B = vector<vector<ll>>(k, vector<ll>(k, inf)); for(int i = 0; i < k; i++) B[i][i] = 0; } node(vector<vector<ll>> _A){ dummy = 0; A = _A; B.assign(k, vector<ll>(k, inf)); for(int i = 0; i < k; i++) B[i][i] = 0; } }; node operator+(node a, node b){ if(a.dummy) return b; if(b.dummy) return a; node rt; rt.dummy = 0; rt.A = a.A, rt.B = vector<vector<ll>>(k, vector<ll>(k, inf)); for(int i = 0; i < k; i++) for(int j = 0; j < k; j++) for(int l = 0; l < k; l++) for(int m = 0; m < k; m++) rt.B[i][j] = min(rt.B[i][j], a.B[i][l]+b.B[m][j]+b.A[l][m]); return rt; } struct segtree{ int k; vector<node> v; segtree(int n){ k = 1; while(k < n) k*=2; k*=2; v.resize(k, node()); } void upd(int in, vector<vector<ll>> x){ in+=k/2; v[in] = node(x); in/=2; while(in > 0){ v[in] = v[2*in]+v[2*in+1]; in/=2; } } node get(int l, int r, int nd, int a, int b){ if(b < l || a > r) return node(); if(a >= l && b <= r) return v[nd]; int md = (a+b)/2; return get(l, r, 2*nd, a, md) + get(l, r, 2*nd+1, md+1, b); } node get(int l, int r){ return get(l, r, 1, 0, k/2-1); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m, o; cin >> k >> n >> m >> o; vector<vector<vector<ll>>> div((n+k-1)/k, vector<vector<ll>>(k, vector<ll>(k, inf))); segtree seg((n+k-1)/k); for(int i = 0; i < m; i++){ int a, b; ll w; cin >> a >> b >> w; div[b/k][a%k][b%k] = w; } for(int i = 0; i < div.size(); i++) seg.upd(i, div[i]); while(o--){ int a, b; cin >> a >> b; auto nd = seg.get(a/k, b/k); ll ans = nd.B[a%k][b%k]; if(ans >= inf) ans = -1; cout << ans << "\n"; } }

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

toll.cpp: In function 'int main()':
toll.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int i = 0; i < div.size(); i++) seg.upd(i, div[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...