Submission #857008
Source Code Expand
Copy
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<assert.h>
#include<sstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define setIO(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
typedef long long ll;
typedef pair<int, int> pii;
const ll LINF = 1e18 + 7;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
//-------------head-------------
int n, m, L, x[N], f[N][20];
int main() {
scanf("%d", &n);
rep(i, 1, n + 1)
scanf("%d", &x[i]);
scanf("%d", &L);
for (int i = n, sum = 0, p = n; i > 0; --i) {
while (sum > L) {
sum -= x[p] - x[p - 1];
--p;
}
f[i][0] = p, sum += x[i] - x[i - 1];
}
for (int j = 1; j < 20; ++j)
for (int i = n; i >= 1; --i)
f[i][j] = f[f[i][j - 1]][j - 1];
scanf("%d", &m);
rep(_m, 0, m)
{
int l, r, ans = 0;
scanf("%d%d", &l, &r);
// printf("l = %d, r = %d\n", l, r);
if (l > r)
swap(l, r);
for (int i = 19; i >= 0; --i)
if (f[l][i] < r) {
ans += 1 << i, l = f[l][i];
// printf("%d ", l);
}
++ans;
printf("%d\n", ans);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Tak and Hotels |
User |
mcginn |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1357 Byte |
Status |
AC |
Exec Time |
147 ms |
Memory |
8960 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:29:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:31:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x[i]);
^
./Main.cpp:32:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &L);
^
./Main.cpp:43:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &m);
^
./Main.cpp:47:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &l, &r);
^
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
500 / 500 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
example_01.txt |
Subtask1 |
example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt |
All |
example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt |
Case Name |
Status |
Exec Time |
Memory |
example_01.txt |
AC |
4 ms |
256 KB |
subtask1_01.txt |
AC |
4 ms |
256 KB |
subtask1_02.txt |
AC |
4 ms |
256 KB |
subtask1_03.txt |
AC |
5 ms |
384 KB |
subtask1_04.txt |
AC |
5 ms |
384 KB |
subtask1_05.txt |
AC |
5 ms |
384 KB |
subtask1_06.txt |
AC |
5 ms |
256 KB |
subtask1_07.txt |
AC |
4 ms |
256 KB |
subtask1_08.txt |
AC |
5 ms |
384 KB |
subtask1_09.txt |
AC |
5 ms |
384 KB |
subtask1_10.txt |
AC |
5 ms |
384 KB |
subtask1_11.txt |
AC |
6 ms |
384 KB |
subtask1_12.txt |
AC |
5 ms |
384 KB |
subtask1_13.txt |
AC |
5 ms |
384 KB |
subtask2_01.txt |
AC |
127 ms |
8832 KB |
subtask2_02.txt |
AC |
140 ms |
8960 KB |
subtask2_03.txt |
AC |
147 ms |
8832 KB |
subtask2_04.txt |
AC |
70 ms |
5760 KB |
subtask2_05.txt |
AC |
91 ms |
5888 KB |
subtask2_06.txt |
AC |
103 ms |
8576 KB |
subtask2_07.txt |
AC |
132 ms |
8960 KB |
subtask2_08.txt |
AC |
135 ms |
8960 KB |
subtask2_09.txt |
AC |
135 ms |
8960 KB |
subtask2_10.txt |
AC |
136 ms |
8960 KB |
subtask2_11.txt |
AC |
131 ms |
8320 KB |
subtask2_12.txt |
AC |
99 ms |
8960 KB |
subtask2_13.txt |
AC |
101 ms |
8576 KB |