QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511354 | #7845. Fast Forward | PonyHex | WA | 1ms | 7784kb | C++14 | 4.3kb | 2024-08-09 19:38:10 | 2024-08-09 19:38:15 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include <chrono>
using namespace std;
std::mt19937_64 rng((std::chrono::steady_clock::now().time_since_epoch().count()));
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define RND mt19937 rnd(0xab8d5f6);
#define time_while(time_while_val) while (((double)clock() - start) / clocks_per_sec < time_while_val)
//#define time_while(time_while_val) while ((double)clock() / clocks_per_sec < time_while_val)//弃
#define rep1(i, n) for(long long i = 1; i <= n; ++i)
#define rep0(i, n) for(long long i = 0; i <= n; ++i)
#define double long double
//#define int long long
//#define ll unsigned long long
#define lc u<<1
#define rc u<<1|1
#define endl "\n"
#define X first
#define Y second
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> PII;
double PI = acos(-1.0);
const double eps = 1e-9;
const ll maxn = 2e6 + 5;
const ll maxm = 2e18;
const ll inf = 2147483647;
const ll mod = 1e9 + 7;
const int dx[] = { 1,0,-1,0,1,1,-1,-1 };//前4为邻
const int dy[] = { 0,-1,0,1,-1,1,-1,1 };
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch>'9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
ll ksm(ll a, ll b) {
ll ans = 1;
ll base = a;
while (b) {
if (b & 1)ans = ans * base % mod;
base = base * base % mod;
b >>= 1;
}
return ans % mod;
}
ll getinv(ll a) {
return ksm(a, mod - 2);
}
void debug(ll ans) {
cout << "业师大人帮你检查答案:" << ans << endl;
}
/*
ll getinv(ll a) {
return ksm(a, mod - 2);
}*/
//dismyth
//警钟长鸣
/*2024/8/6
待补:cdq分治补不出来,三维偏序,平衡树->link cut tree*/
/*待补 324(包括f),310,313,315,317*///好多,但是每天得vp,强度得上去
/*306d,344d*/
//赛时多出,赛后少补
//vp一把
/*
struct cmp {
bool operator()(pair<ll, ll> a, pair<ll, ll> b) {
//return a.X > b.X;//表示小根堆
}
};*/
//异或是可叠加的,所以异或是可求前缀和的
//注意map初始化为0遇到ans为0时记忆化会失效,这时候我们就要用到.count
//re.count({l,r})
int a[maxn];
int n, m;
bool vis[maxn];
int ans[maxn];
vector<int>mid;
void dfs(int now) {
mid.push_back(a[now]);
if (vis[now] || now > n) {//走过了,我们,依然要向后走
int mm = now;
int cnt = 0;
while (mm < now + n) {
int pos = lower_bound(a + 1, a + 1 + 2 * n, a[mm] + m) - a;
if (pos == 1 + 2 * n) {
cnt++;
mid.push_back(1e9 + 5); break;
}
mid.push_back(a[pos]);
mm = pos;
cnt++;
}
ans[now] = cnt;
if (a[now] - a[now - 1] >= m)ans[now]++;
return;
}//退出
vis[now] = 1;
int pos = lower_bound(a + 1, a + 1 + 2 * n, a[now] + m) - a;
//mid.push_back(a[pos]);
dfs(pos);
ans[now] = (lower_bound(mid.begin(), mid.end(), a[now+n-1])) - (lower_bound(mid.begin(), mid.end(), a[now]));
if (a[now] - a[now - 1] >= m) {
ans[now]++;
}
return;
}
//RND;
void solve() {
//我应该直接走,就是,对于每一个位置,我们都尝试去向前走
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i]; a[i + n] = a[i];
}
a[0] = 0;
for (int i = 1; i <= 2 * n; i++) {
a[i] += a[i - 1]; vis[i] = 0;
}
vis[0] = 0;
//获取前缀和,然后对于其中的元素,没走过就一直走
//但是我们怎么记录ans
for (int i = 1; i <= n; i++) {
if (vis[i] == 0) {
dfs(i);
mid.clear();
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] - 1 << " ";
}
cout << endl;
return;
}
signed main() {
IOS;
ll t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
/*致我已死的友人*/
/*PonyHex*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7684kb
input:
7 7 1 1 1 1 1 1 1
output:
0 0 0 0 0 0 0
result:
ok single line: '0 0 0 0 0 0 0 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 7784kb
input:
3 3 1 1 3
output:
0 1 1
result:
ok single line: '0 1 1 '
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7784kb
input:
10 5 4 1 5 5 1 3 2 1 5 2
output:
4 4 5 4 4 4 4 4 5 4
result:
wrong answer 1st lines differ - expected: '5 4 5 4 4 5 4 4 5 4', found: '4 4 5 4 4 4 4 4 5 4 '