1 条题解
-
0
Answer is here!
#include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef pair <int, int> pii; int read() { int res = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch - '0'); return res * f; } const int N = 3e5 + 5; const int INF = 0x3f3f3f3f; int n; int a[N]; int mi[N], mn[N]; int main() { int i, k; n = read(); for (i = 1; i <= n; i ++) a[i] = read(); mn[n + 1] = INF; for (i = n; i >= 1; i --) { mn[i] = mn[i + 1]; mi[i] = mi[i + 1]; if (i - a[i] < mn[i]) { mn[i] = i - a[i]; mi[i] = i; } } for (i = 1; i <= n; i ++) { k = max(a[i] + i, 1); if (i >= mn[k] && k <= n) printf("1 %d\n", mi[k] - i); else printf("0\n"); } return 0; }
Thank you!
- 1
信息
- ID
- 76
- 时间
- 3000ms
- 内存
- 512MiB
- 难度
- 4
- 标签
- 递交数
- 813
- 已通过
- 142
- 上传者