#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e17;
const int mod2 = 1e9 + 9;
const int mod1 = 998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, l, r, mid, l2, r2, center;
int i, s10, s12,k1,k2,s11;
int kk;
int el = 19;
main()
{
// fin(task);
// fou(task);
NHP
/// cin>>s1;
///modwwe
phongbeo();
// checktime
}
int s,t;
vector<ib> a[100001];
int b[100001];
vector<int> c[100001];
ib d[100001];
ib st[17][100001];
vector<int> vv;
bool cmp(ib a,ib b)
{
return a.a<b.a;
}
void phongbeo()
{
cin>>n>>t;
for(int i=1; i<n; i++)
{
cin>>k;
b[i]=k;
a[i].resize(k+1);
c[i].resize(k+1);
s9+=k;
for(int j=1; j<=k; j++)
cin>>a[i][j].a>>a[i][j].b,c[i][j]=++dem,d[dem]= {i,j};
sort(a[i].begin()+1,a[i].end(),cmp);
for(int j=k-1; j>=1; --j)
a[i][j].b=min(a[i][j].b,a[i][j+1].b);
}
for(int i=1; i<n-1; i++)
{
vv.clear();
for(int j=1; j<=b[i+1]; j++)
vv.pb(a[i+1][j].a);
for(int j=1; j<=b[i]; j++)
{
if(a[i][j].b>vv.back())
{
s3=vv[0]+t-a[i][j].a;
st[0][c[i][j]]= {c[i+1][1],s3};
}
else
{
s2=lower_bound(vv.begin(),vv.end(),a[i][j].b)-vv.begin()+1;
s3=a[i+1][s2].a-a[i][j].a;
st[0][c[i][j]]= {c[i+1][s2],s3};
}
}
}
for(int i=1; i<17; i++)
for(int j=1; j<=s9; j++)
st[i][j].a=st[i-1][st[i-1][j].a].a,
st[i][j].b=st[i-1][j].b+st[i-1][st[i-1][j].a].b;
cin>>m;
for(int i=1; i<=m; i++)
{
cin>>l>>r;
if(l==r)
{
cout<<0,down continue;
}
for(int j=1; j<=b[l]; j++)
{
s=r-l-1;
s3=c[l][j];
s4=0;/// 3->4->0
for(s;s;s-=s&-s){
int f=31-__builtin_clz(s&-s);
s4+=st[f][s3].b;
s3=st[f][s3].a;
}
if(j==1)s5=s4+a[r-1][d[s3].b].b-a[r-1][d[s3].b].a;
else s5=min(s4+a[r-1][d[s3].b].b-a[r-1][d[s3].b].a,s5);
}
cout<<s5,down
}
}
Compilation message
Main.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main()
| ^~~~
Main.cpp: In function 'void phongbeo()':
Main.cpp:141:17: warning: statement has no effect [-Wunused-value]
141 | for(s;s;s-=s&-s){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5216 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
51 ms |
10584 KB |
Output is correct |
4 |
Correct |
70 ms |
12372 KB |
Output is correct |
5 |
Correct |
61 ms |
11092 KB |
Output is correct |
6 |
Correct |
77 ms |
12368 KB |
Output is correct |
7 |
Correct |
77 ms |
12480 KB |
Output is correct |
8 |
Correct |
56 ms |
10580 KB |
Output is correct |
9 |
Correct |
80 ms |
12372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5216 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
51 ms |
10584 KB |
Output is correct |
4 |
Correct |
70 ms |
12372 KB |
Output is correct |
5 |
Correct |
61 ms |
11092 KB |
Output is correct |
6 |
Correct |
77 ms |
12368 KB |
Output is correct |
7 |
Correct |
77 ms |
12480 KB |
Output is correct |
8 |
Correct |
56 ms |
10580 KB |
Output is correct |
9 |
Correct |
80 ms |
12372 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
73 ms |
11660 KB |
Output is correct |
12 |
Correct |
72 ms |
11576 KB |
Output is correct |
13 |
Correct |
71 ms |
11412 KB |
Output is correct |
14 |
Correct |
72 ms |
11448 KB |
Output is correct |
15 |
Correct |
70 ms |
11856 KB |
Output is correct |
16 |
Correct |
48 ms |
9296 KB |
Output is correct |
17 |
Correct |
73 ms |
12272 KB |
Output is correct |
18 |
Correct |
67 ms |
11860 KB |
Output is correct |
19 |
Correct |
73 ms |
12132 KB |
Output is correct |
20 |
Correct |
73 ms |
11928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5216 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
51 ms |
10584 KB |
Output is correct |
4 |
Correct |
70 ms |
12372 KB |
Output is correct |
5 |
Correct |
61 ms |
11092 KB |
Output is correct |
6 |
Correct |
77 ms |
12368 KB |
Output is correct |
7 |
Correct |
77 ms |
12480 KB |
Output is correct |
8 |
Correct |
56 ms |
10580 KB |
Output is correct |
9 |
Correct |
80 ms |
12372 KB |
Output is correct |
10 |
Correct |
184 ms |
41152 KB |
Output is correct |
11 |
Correct |
314 ms |
51820 KB |
Output is correct |
12 |
Correct |
311 ms |
51792 KB |
Output is correct |
13 |
Correct |
262 ms |
49748 KB |
Output is correct |
14 |
Correct |
286 ms |
51796 KB |
Output is correct |
15 |
Correct |
332 ms |
51796 KB |
Output is correct |
16 |
Correct |
184 ms |
41300 KB |
Output is correct |
17 |
Correct |
289 ms |
51952 KB |
Output is correct |
18 |
Correct |
109 ms |
42496 KB |
Output is correct |
19 |
Correct |
87 ms |
42068 KB |
Output is correct |
20 |
Correct |
100 ms |
42404 KB |
Output is correct |
21 |
Correct |
105 ms |
42580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5216 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
51 ms |
10584 KB |
Output is correct |
4 |
Correct |
70 ms |
12372 KB |
Output is correct |
5 |
Correct |
61 ms |
11092 KB |
Output is correct |
6 |
Correct |
77 ms |
12368 KB |
Output is correct |
7 |
Correct |
77 ms |
12480 KB |
Output is correct |
8 |
Correct |
56 ms |
10580 KB |
Output is correct |
9 |
Correct |
80 ms |
12372 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
73 ms |
11660 KB |
Output is correct |
12 |
Correct |
72 ms |
11576 KB |
Output is correct |
13 |
Correct |
71 ms |
11412 KB |
Output is correct |
14 |
Correct |
72 ms |
11448 KB |
Output is correct |
15 |
Correct |
70 ms |
11856 KB |
Output is correct |
16 |
Correct |
48 ms |
9296 KB |
Output is correct |
17 |
Correct |
73 ms |
12272 KB |
Output is correct |
18 |
Correct |
67 ms |
11860 KB |
Output is correct |
19 |
Correct |
73 ms |
12132 KB |
Output is correct |
20 |
Correct |
73 ms |
11928 KB |
Output is correct |
21 |
Correct |
184 ms |
41152 KB |
Output is correct |
22 |
Correct |
314 ms |
51820 KB |
Output is correct |
23 |
Correct |
311 ms |
51792 KB |
Output is correct |
24 |
Correct |
262 ms |
49748 KB |
Output is correct |
25 |
Correct |
286 ms |
51796 KB |
Output is correct |
26 |
Correct |
332 ms |
51796 KB |
Output is correct |
27 |
Correct |
184 ms |
41300 KB |
Output is correct |
28 |
Correct |
289 ms |
51952 KB |
Output is correct |
29 |
Correct |
109 ms |
42496 KB |
Output is correct |
30 |
Correct |
87 ms |
42068 KB |
Output is correct |
31 |
Correct |
100 ms |
42404 KB |
Output is correct |
32 |
Correct |
105 ms |
42580 KB |
Output is correct |
33 |
Correct |
218 ms |
46140 KB |
Output is correct |
34 |
Correct |
229 ms |
46044 KB |
Output is correct |
35 |
Correct |
200 ms |
42676 KB |
Output is correct |
36 |
Correct |
202 ms |
42836 KB |
Output is correct |
37 |
Correct |
224 ms |
43848 KB |
Output is correct |
38 |
Correct |
193 ms |
39764 KB |
Output is correct |
39 |
Correct |
256 ms |
49236 KB |
Output is correct |
40 |
Correct |
206 ms |
35668 KB |
Output is correct |
41 |
Correct |
177 ms |
38740 KB |
Output is correct |
42 |
Correct |
278 ms |
49236 KB |
Output is correct |
43 |
Correct |
211 ms |
45360 KB |
Output is correct |
44 |
Correct |
241 ms |
47184 KB |
Output is correct |
45 |
Correct |
102 ms |
40380 KB |
Output is correct |
46 |
Correct |
92 ms |
38480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5212 KB |
Output is correct |
3 |
Correct |
325 ms |
35924 KB |
Output is correct |
4 |
Correct |
320 ms |
35920 KB |
Output is correct |
5 |
Correct |
322 ms |
35892 KB |
Output is correct |
6 |
Correct |
331 ms |
35900 KB |
Output is correct |
7 |
Correct |
316 ms |
35664 KB |
Output is correct |
8 |
Correct |
341 ms |
35928 KB |
Output is correct |
9 |
Correct |
303 ms |
36128 KB |
Output is correct |
10 |
Execution timed out |
3047 ms |
33436 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5216 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
51 ms |
10584 KB |
Output is correct |
4 |
Correct |
70 ms |
12372 KB |
Output is correct |
5 |
Correct |
61 ms |
11092 KB |
Output is correct |
6 |
Correct |
77 ms |
12368 KB |
Output is correct |
7 |
Correct |
77 ms |
12480 KB |
Output is correct |
8 |
Correct |
56 ms |
10580 KB |
Output is correct |
9 |
Correct |
80 ms |
12372 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
73 ms |
11660 KB |
Output is correct |
12 |
Correct |
72 ms |
11576 KB |
Output is correct |
13 |
Correct |
71 ms |
11412 KB |
Output is correct |
14 |
Correct |
72 ms |
11448 KB |
Output is correct |
15 |
Correct |
70 ms |
11856 KB |
Output is correct |
16 |
Correct |
48 ms |
9296 KB |
Output is correct |
17 |
Correct |
73 ms |
12272 KB |
Output is correct |
18 |
Correct |
67 ms |
11860 KB |
Output is correct |
19 |
Correct |
73 ms |
12132 KB |
Output is correct |
20 |
Correct |
73 ms |
11928 KB |
Output is correct |
21 |
Correct |
184 ms |
41152 KB |
Output is correct |
22 |
Correct |
314 ms |
51820 KB |
Output is correct |
23 |
Correct |
311 ms |
51792 KB |
Output is correct |
24 |
Correct |
262 ms |
49748 KB |
Output is correct |
25 |
Correct |
286 ms |
51796 KB |
Output is correct |
26 |
Correct |
332 ms |
51796 KB |
Output is correct |
27 |
Correct |
184 ms |
41300 KB |
Output is correct |
28 |
Correct |
289 ms |
51952 KB |
Output is correct |
29 |
Correct |
109 ms |
42496 KB |
Output is correct |
30 |
Correct |
87 ms |
42068 KB |
Output is correct |
31 |
Correct |
100 ms |
42404 KB |
Output is correct |
32 |
Correct |
105 ms |
42580 KB |
Output is correct |
33 |
Correct |
218 ms |
46140 KB |
Output is correct |
34 |
Correct |
229 ms |
46044 KB |
Output is correct |
35 |
Correct |
200 ms |
42676 KB |
Output is correct |
36 |
Correct |
202 ms |
42836 KB |
Output is correct |
37 |
Correct |
224 ms |
43848 KB |
Output is correct |
38 |
Correct |
193 ms |
39764 KB |
Output is correct |
39 |
Correct |
256 ms |
49236 KB |
Output is correct |
40 |
Correct |
206 ms |
35668 KB |
Output is correct |
41 |
Correct |
177 ms |
38740 KB |
Output is correct |
42 |
Correct |
278 ms |
49236 KB |
Output is correct |
43 |
Correct |
211 ms |
45360 KB |
Output is correct |
44 |
Correct |
241 ms |
47184 KB |
Output is correct |
45 |
Correct |
102 ms |
40380 KB |
Output is correct |
46 |
Correct |
92 ms |
38480 KB |
Output is correct |
47 |
Correct |
3 ms |
5212 KB |
Output is correct |
48 |
Correct |
2 ms |
5212 KB |
Output is correct |
49 |
Correct |
325 ms |
35924 KB |
Output is correct |
50 |
Correct |
320 ms |
35920 KB |
Output is correct |
51 |
Correct |
322 ms |
35892 KB |
Output is correct |
52 |
Correct |
331 ms |
35900 KB |
Output is correct |
53 |
Correct |
316 ms |
35664 KB |
Output is correct |
54 |
Correct |
341 ms |
35928 KB |
Output is correct |
55 |
Correct |
303 ms |
36128 KB |
Output is correct |
56 |
Execution timed out |
3047 ms |
33436 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |