QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#852361#32. TollDarsh_Jain7 224ms312652kbC++205.8kb2025-01-11 11:32:002025-01-11 11:32:00

Judging History

你现在查看的是最新测评结果

  • [2025-01-11 11:32:00]
  • 评测
  • 测评结果:7
  • 用时:224ms
  • 内存:312652kb
  • [2025-01-11 11:32:00]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define fr(j, l,n) for(int j = l; j < int(n); j++)
#define fn(j,n,l) for(int j=n-1;j>=l;j--) 
#define gets(s) string s; cin>>s;
#define all(v) v.begin(),v.end()
#define getv(v,n) vector<ll> v(n); fr(i,0,n) cin >> v[i];
#define seev(a) for(auto x:a){cout<<x<<" ";}cout<<endl;
#define vl vector<ll>
#define ve vector
#define vvl vector<vector<ll>>
#define vp vector<pair<ll,ll>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pb push_back
#define mp make_pair
#define mse multiset<ll>
#define se set<ll>
#define ma map<ll,ll>
#define getmat(v,n,m) vector<vl>v(n,vl(m));fr(i,0,n) {fr (j,0,m) cin>>v[i][j];}
#define seemat(mat) for(auto row:mat){seev(row);}
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
using namespace std;
using namespace __gnu_pbds;

// Define ordered multiset with long long

typedef tree<long long, long long, less<long>, rb_tree_tag, tree_order_statistics_node_update> ordered_multimap;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vl sieve;
void SieveOfEratosthenes(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    vl prime(n+1,true);
 
    for (int p = 2; p * p <= n; p++) {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true) {
            // Update all multiples of p greater than or
            // equal to the square of it numbers which are
            // multiple of p and are less than p^2 are
            // already been marked.
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
 
    // Print all prime numbers
    for (int p = 2; p <= n; p++)
        if (prime[p])
            sieve.push_back(p);
}
bool sortbysec(const pair<ll, ll>& a,
               const pair<ll, ll>& b)
{
    return (a.second < b.second);
}
// gives gcd and the other coefficients
ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
// a raised to power b
ll pwr(ll a, ll b, ll mod = 0){
    ll result = 1;
    if(mod == 0){
        while(b){
            if(b & 1) result *= a;
            a *= a;
            b = b >> 1;
        }
    }
    else {
        while(b){
            if(b & 1){
                result *= a;
                result  = result % mod;
            }
            a *= a;
            a = a % mod;
            b = b >> 1;
        }
    }
    return result;
}
ll modularinverse(ll a,ll p)// p is prime
{
    return pwr(a,p-2,p);
}
// to convert string to binary(63 bits)
string tobin(ll a)
{
    string s;
    for (int i = 0; i < 63; i++)
    {
        if(a%2==1)
        {
            s+='1';
        }
        else
        {
            s+='0';
        }
        a>>=1;
    }
    return s;
}
int log2_floor(unsigned long long i) {
    return i ? 63 - __builtin_clzll(i) : -1;
    // -1 as log undefined for 0
}
// QUESTION DHANG SE PADHNA
void combine(vvl &a, vvl &b, ll &k, vvl &c)
{
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            for (int jj = 0; jj < k; jj++)
            {
                c[i][j]=min(c[i][j],a[i][jj]+b[jj][j]);
            }
        }
        
        
    }
    
}
void solve(ll tc){
    ll n=0,m=0,k=0,a=0,b=0,c=0,x=0,y=0,z=0,o;
    cin>>k>>n>>m>>o;
    ve<vp> gr(n);
    ve<ve<vvl>>dist(n,ve<vvl> (log2_floor(n)+1,vvl(5,vl(5,1e18))));
    for (int i = 0; i < m; i++)
    {
        cin>>a>>b>>x;
        // gr[a].pb({b,x});
        dist[a/k][0][a%k][b%k]=x;
    }
    
    // cout<<'w'<<endl;
    for(int j=0;j<dist[0].size()-1;j++)
    {
        for (int i = 0; i < n/k; i++)
        {
            if((i+(1<<(j)))<n)
            {
                // cout<<i<<' '<<(1<<j)<<endl;
                combine(dist[i][j],dist[(i+(1<<(j)))][j],k,dist[i][j+1]);
            }
        }
    }
    // for (int i = 0; i < n; i++)
    // {
    //     cout<<i<<' '<<endl;
    //     // vvl ans(k,vl(k,1e18));
    //     // combine(dist[i][0],dist[i+1][0],k,ans);
    //     // seemat(ans);
    //     // cout<<endl;
    //     seemat(dist[i][1]);

    // }
    
    for (int i = 0; i < o; i++)
    {
        cin>>x>>y;
        vvl ans(k,vl(k, 1e18));
        vvl ans2(k,vl(k, 0));
        c=x/k,z=y/k;
        ll inix=x,iniy=y;
        for (int j = 0; j < dist[0].size(); j++)
        {
            // cout<<z<<' '<<c<<endl;
            if((z-c) &  (1<<j))
            {
                combine(ans2,dist[c][j],k,ans);
                // x+=1<<j;
                c+=(1<<j);
                swap(ans2,ans);
                for (int jj = 0; jj < k; jj++)
                {
                    for (int ii = 0; ii < k; ii++)
                    {
                        ans[jj][ii]=1e18;
                    }
                }
            }
        }
        // seemat(ans2);
        if(inix/k==iniy/k)
        {
            cout<<-1<<endl;
        }
        else
        {
            if(ans2[inix%k][iniy%k]==1e18)
            {
                cout<<-1<<endl;
            }
            else
            {
                cout<<ans2[inix%k][iniy%k]<<endl;
            }
        }
    }
    

}


int main(){

#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int t=1;
// cin>>t;
ll tc=0;
while(t--){
    tc++;
    solve(tc);
}

return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 193ms
memory: 312468kb

input:

1 50000 49999 10000
28116 28117 4272
15866 15867 5673
38118 38119 8922
38575 38576 806
26221 26222 8045
16395 16396 211
17070 17071 1801
24810 24811 6670
44898 44899 6603
36986 36987 5958
5058 5059 5472
38952 38953 7947
25479 25480 937
34813 34814 8087
36873 36874 9102
38090 38091 4416
43253 43254 5...

output:

132581784
25180897
90096323
137505791
182756627
56626936
92687360
213071340
230587686
133760598
165611824
64778884
242205990
81064064
101519576
9635466
101928710
32361680
148988187
70570739
84559353
27969941
70881194
192597213
168605876
70339228
177355217
144544606
63764960
85559057
47845102
1259524...

result:

ok 10000 lines

Test #2:

score: 7
Accepted
time: 0ms
memory: 3536kb

input:

1 10 6 10
6 7 6635
7 8 4970
0 1 6312
8 9 7809
2 3 664
1 2 6891
8 9
2 4
5 7
5 6
5 9
3 8
0 8
0 1
3 9
2 8

output:

7809
-1
-1
-1
-1
-1
-1
6312
-1
-1

result:

ok 10 lines

Test #3:

score: 7
Accepted
time: 0ms
memory: 3600kb

input:

1 10 7 10
8 9 1074
3 4 2137
6 7 7767
5 6 9895
1 2 9710
4 5 6062
2 3 8917
2 3
2 8
1 2
4 7
2 5
2 7
3 4
6 8
6 9
5 8

output:

8917
-1
9710
23724
17116
34778
2137
-1
-1
-1

result:

ok 10 lines

Test #4:

score: 7
Accepted
time: 0ms
memory: 3644kb

input:

1 10 4 10
3 4 6490
5 6 2540
7 8 1090
2 3 1691
1 4
6 8
3 7
0 4
6 7
2 3
0 1
0 7
4 8
2 5

output:

-1
-1
-1
-1
-1
1691
-1
-1
-1
-1

result:

ok 10 lines

Test #5:

score: 7
Accepted
time: 0ms
memory: 7412kb

input:

1 1000 949 1000
473 474 6082
710 711 2134
433 434 714
567 568 5179
408 409 3769
513 514 6321
401 402 8814
988 989 6244
178 179 563
158 159 7702
263 264 591
879 880 6393
802 803 3905
573 574 1932
773 774 6873
205 206 7370
522 523 9710
461 462 9092
872 873 1984
255 256 11
280 281 7660
591 592 4640
519...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
27903
-1
-1
-1
-1
100126
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok 1000 lines

Test #6:

score: 7
Accepted
time: 4ms
memory: 7464kb

input:

1 999 948 1000
749 750 8886
67 68 9787
185 186 1131
460 461 1811
952 953 8489
35 36 1599
821 822 6767
864 865 8214
140 141 9881
586 587 8319
896 897 1414
613 614 3940
423 424 2063
991 992 4634
16 17 8820
826 827 8163
327 328 8776
212 213 8232
610 611 7322
693 694 9657
668 669 444
871 872 8760
101 10...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
63690
-1
-1
-1
-1
-1
-1
-1
193476
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
117233
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
39568
-...

result:

ok 1000 lines

Test #7:

score: 7
Accepted
time: 0ms
memory: 7768kb

input:

1 1001 980 1000
481 482 4104
787 788 4428
513 514 908
583 584 3768
143 144 7946
715 716 4085
877 878 3716
760 761 3605
228 229 8237
206 207 4338
95 96 7475
889 890 3363
278 279 2082
752 753 1962
531 532 8964
968 969 572
497 498 8302
20 21 6956
101 102 995
221 222 8494
113 114 8089
837 838 4126
30 31...

output:

-1
57565
-1
-1
-1
-1
131431
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
144425
-1
-1
-1
-1
247166
-1
-1
-1
-1
-1
64718
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
50372
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 1000 lines

Test #8:

score: 7
Accepted
time: 190ms
memory: 312616kb

input:

1 50000 49949 10000
22175 22176 7071
44427 44428 6667
20106 20107 8044
28928 28929 3806
35990 35991 8500
13247 13248 5160
10180 10181 8548
41465 41466 9259
24149 24150 5265
43232 43233 5623
41789 41790 2816
35050 35051 501
23410 23411 3928
39593 39594 4752
51 52 9779
15937 15938 2958
3718 3719 4988
...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
562761
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3241138
-1
143562
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
9081955
-1
-1
-1
-1
4052571
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok 10000 lines

Test #9:

score: 7
Accepted
time: 196ms
memory: 312612kb

input:

1 49999 47498 10000
11534 11535 4097
49126 49127 1935
14597 14598 3715
46122 46123 18
9969 9970 6602
27587 27588 5680
10039 10040 3402
47097 47098 9593
28008 28009 6729
39859 39860 3158
13444 13445 8707
1197 1198 1229
40425 40426 408
19235 19236 5707
45808 45809 9761
25095 25096 9289
11944 11945 248...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 10000 lines

Test #10:

score: 7
Accepted
time: 165ms
memory: 312464kb

input:

1 49999 0 10000
11705 30866
2730 32279
32802 46874
670 19831
7600 7743
24917 31066
32253 48714
35896 49551
34066 36763
27736 49552
3699 4980
433 39378
12731 21521
12403 18096
22278 36165
18691 28349
1225 43408
2085 41693
5173 39213
19930 36188
14465 22777
4510 35701
21899 45888
19047 44658
22130 262...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 10000 lines

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 224ms
memory: 312652kb

input:

2 50000 94996 10000
42590 42592 9309
11538 11541 4653
45675 45677 3309
869 870 6588
30563 30565 8686
30988 30991 9038
4495 4497 5335
25643 25644 6179
4890 4892 7897
18593 18594 2267
23266 23268 3778
42163 42164 8391
560 562 3808
48478 48480 7402
29601 29603 6345
42660 42662 6049
34298 34301 8993
152...

output:

9660551
-1
-1
29677497
-1
-1
25954841
-1
29026387
-1
-1
25117089
-1
2180255
8821457
-1
17974797
-1
31676013
22691306
-1
-1
22125829
21517896
-1
-1
-1
-1
12698182
19407256
12975298
-1
-1
-1
26717226
23860276
5148244
-1
-1
14080996
9293646
-1
-1
-1
-1
-1
19509063
-1
22475995
-1
35380640
17543002
19699...

result:

wrong answer 9343rd lines differ - expected: '9500', found: '7619'

Subtask #3:

score: 0
Wrong Answer

Test #27:

score: 8
Accepted
time: 0ms
memory: 3812kb

input:

1 10 8 10
7 8 2626
0 1 4605
3 4 1319
4 5 1214
5 6 4454
6 7 4600
8 9 6857
1 2 2017
3 4
2 9
0 7
0 5
4 5
1 8
4 6
7 8
1 2
4 6

output:

1319
-1
-1
-1
1214
-1
5668
2626
2017
5668

result:

ok 10 lines

Test #28:

score: 0
Wrong Answer
time: 0ms
memory: 3652kb

input:

2 10 14 10
3 4 5032
0 2 6758
6 9 3324
0 3 2553
1 2 6681
2 4 2802
7 8 7419
2 5 680
7 9 2800
4 6 8953
4 7 409
3 5 2008
5 6 4066
5 7 7370
0 7
3 9
1 5
4 7
2 6
2 3
6 9
7 8
7 8
1 2

output:

7994
6011
4561
409
4746
-1
2800
7419
7419
6681

result:

wrong answer 2nd lines differ - expected: '8241', found: '6011'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%