Submission #668262

#TimeUsernameProblemLanguageResultExecution timeMemory
668262ktkeremToll (BOI17_toll)C++17
100 / 100
264 ms23704 KiB
/*#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/ #include<bits/stdc++.h> /**/ //typedef int ll; typedef long long ll; typedef unsigned long long ull; typedef std::string str; //typedef vector<std::vector<ll>> vv; /*typedef __int128 vll; typedef unsigned __int128 uvll;*/ #define llll std::pair<ll , ll> #define pb push_back #define pf push_front #define halo cout << "hello\n" #define fi first #define sec second #define vv(x) std::vector<std::vector<x>> #define all(a) a.begin() , a.end() const ll limit = 1e15+7; const ll ous = 3e5 + 7; const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1}; ll n , m , k , o; std::vector<std::vector<std::vector<ll>>> valt , ar; std::vector<std::vector<ll>> mult(std::vector<std::vector<ll>> a , std::vector<std::vector<ll>> b){ std::vector<std::vector<ll>> res(k , std::vector<ll>(k , limit)); for(ll i = 0;k>i;i++){ for(ll j = 0;k>j;j++){ ll cur = limit; for(ll tt =0;k>tt;tt++){ cur = std::min(cur , a[i][tt] + b[tt][j]); } res[i][j] = cur; } } return res; } void build(ll l , ll r , ll a){ if(l == r){ valt[a] = ar[l]; return; } ll md = (l + r)/2; build(l , md , a*2); build(md+1 , r , a*2+1); valt[a] = mult(valt[a*2] , valt[a*2+1]); return; } std::vector<std::vector<ll>> rq(ll l , ll r , ll nl , ll nr , ll a){ if(nl > r || nr < l){ std::vector<std::vector<ll>> rte(k , std::vector<ll>(k , limit)); for(ll i = 0;k>i;i++){ rte[i][i] = 0; } return rte; } if(l <= nl && r >= nr){ return valt[a]; } ll md = (nl + nr)/2; std::vector<std::vector<ll>> f = rq(l , r , nl , md , a*2) , s = rq(l , r , md+1 , nr , a*2+1); return mult(f , s); } void solve(){ std::cin >> k >> n >> m >> o; ar.resize(n/k+15 , std::vector<std::vector<ll>>(k , std::vector<ll>(k , limit))); valt.resize((n/k+1) * 4 , std::vector<std::vector<ll>>(k , std::vector<ll>(k , limit))); for(ll i = 0;m>i;i++){ ll x , y , z;std::cin >> x >> y >> z; ar[x/k][x%k][y%k] = std::min(ar[x/k][x%k][y%k] , z); } /*for(ll i = 0;n/k>=i;i++){ for(ll j = 0;k>j;j++){ for(ll tso = 0;k>tso;tso++){ std::cout << ar[i][j][tso] << " "; } std::cout << "\n"; } std::cout << "\n"; }*/ build(0 , (n-1)/k , 1); while(o--){ ll x , y;std::cin >> x >> y; if(x/k >= y/k){ std::cout << -1 << "\n"; } else{ std::vector<std::vector<ll>> bt = rq(x/k , y/k - 1 , 0 , (n-1)/k , 1); /*for(ll j = 0;k>j;j++){ for(ll tso = 0;k>tso;tso++){ std::cout << bt[j][tso] << " "; } std::cout << "\n"; }*/ if(bt[x%k][y%k] < limit){ std::cout << bt[x%k][y%k] << "\n"; } else{ std::cout << -1 << "\n"; } } } return;/**/ } signed main(){ std::ios_base::sync_with_stdio(false);std::cin.tie(NULL); ll t=1; //std::cin >> t; ll o = 1; while(t--){ //cout << "Case " << o++ << ":\n"; solve(); } return 0; }/**/

Compilation message (stderr)

toll.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
toll.cpp: In function 'int main()':
toll.cpp:112:8: warning: unused variable 'o' [-Wunused-variable]
  112 |     ll o = 1;
      |        ^
#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...