Submission #714518

#TimeUsernameProblemLanguageResultExecution timeMemory
714518lukameladzeToll (BOI17_toll)C++14
49 / 100
1961 ms22740 KiB
# include <bits/stdc++.h> using namespace std; #define f first #define s second // #define int long long #define pii pair <int, int> #define pb push_back const int N = 2e5 + 5, inf = 1e9; int t,n,k,a[N], m, q, x; vector <vector <int> > tree[N], zer_vii; vector <vector <int> > merge(vector <vector <int> > a, vector <vector <int> > b) { vector <vector <int> > res; res = vector < vector <int> > (k, vector <int> (k, inf)); zer_vii = vector < vector <int> > (k, vector <int> (k, inf)); for (int i = 0; i < k; i++) zer_vii[i][i] = 0; for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { for (int m = 0; m < k; m++) { res[i][j] = min(res[i][j], a[i][m] + b[m][j]); } } } return res; } void build(int node, int le, int ri) { tree[node] = vector < vector <int> > (k, vector <int> (k, inf)); if (le == ri) { return ; } int mid = (le + ri) / 2; build(2 * node, le, mid); build(2 * node + 1, mid + 1, ri); } void update(int node, int le, int ri, int idxa, int rema, int idxb, int remb, int val) { if (le > idxa || ri < idxa) return ; if (le == ri) { tree[node][rema][remb] = min(tree[node][rema][remb], val); return ; } int mid = (le + ri) / 2; update(2 * node, le, mid, idxa, rema, idxb, remb, val); update(2 * node + 1, mid + 1, ri, idxa, rema, idxb, remb, val); tree[node] = merge(tree[2 * node], tree[2 * node + 1]); } vector <vector <int> > getans(int node, int le, int ri, int start, int end) { if (le > end || ri < start) return zer_vii; if (le >= start && ri <= end) { return tree[node]; } int mid = (le + ri) / 2; vector <vector <int> > p1, p2, res; p1 = getans(2 * node, le, mid, start, end); p2 = getans(2 * node + 1, mid + 1, ri, start, end); res = merge(p1, p2); return res; } main() { std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>k>>n>>m>>q; build(1, 0, (n - 1) / k); for (int i = 1; i <= m; i++) { int a, b, x; cin>>a>>b>>x; update(1, 0, (n - 1) / k, a / k, a % k, b / k, b % k, x); } while (q--) { int a, b; cin>>a>>b; vector <vector <int> > ans; ans = getans(1, 0, (n - 1) / k, a / k, b / k - 1); cout<<(ans[a % k][b % k] < inf ? ans[a % k][b % k] : -1)<<"\n"; } }

Compilation message (stderr)

toll.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main() {
      | ^~~~
#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...