QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511396 | #7845. Fast Forward | PonyHex | TL | 1ms | 7796kb | C++14 | 4.3kb | 2024-08-09 20:28:16 | 2024-08-09 20:28:17 |
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})
ll n, m;
int a[maxn];
bool vis[maxn];
int ans[maxn];
vector<int>mid;
void dfs(ll now) {
mid.push_back(a[now]);
if (vis[now] || now > n) {
ll pos = now;/*
for (int i = 0; i < mid.size(); i++)cout << mid[i] << " ";
cout << endl << endl;*/
while (pos <= n * 2 && pos <= now + n) {
ll newpos = lower_bound(a + 1, a + 1 + 2 * n, a[pos] + m) - a;
if (newpos > 2 * n)break;
mid.push_back(a[newpos]);
pos = newpos;
}/*
for (int i = 0; i < mid.size(); i++)cout << mid[i] << " ";
cout << endl << endl;*/
return;
}
vis[now] = 1;
ll pos = lower_bound(a + 1, a + 1 + 2 * n, a[now] + m)-a;
dfs(pos);
ans[now] = lower_bound(mid.begin(),mid.end(), a[now + n]) - lower_bound(mid.begin(), mid.end(), a[now]);
/*
for (int i = 0; i <mid.size(); i++)cout << mid[i] << " ";
cout << endl;*/
return;
}
//RND;
void solve() {
//重新写,好乱
cin >> n >> m; ll sum = 0;
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i]; a[i + n] = a[i];
sum += a[i];
}
for (int i = 1; i <= n * 2; i++)a[i] += a[i - 1];
if (sum <= m) {
cout << 0;
for (int i = 2; i <= n; i++) {
cout << " " << 0;
}cout << endl; return;
}
for (int i = 1; i <= n; i++)vis[i] = 0;
vis[0] = 0;
//这样就不用考虑到二分找不到的情况了
for (int i = 0; i < n; i++) {
if (vis[i] == 0) {
dfs(i);
mid.clear();
//debug(1);
}
}
for (int i = 0; i <= n - 1; 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: 0ms
memory: 5760kb
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: 7716kb
input:
3 3 1 1 3
output:
0 1 1
result:
ok single line: '0 1 1 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 7796kb
input:
10 5 4 1 5 5 1 3 2 1 5 2
output:
5 4 5 4 4 5 4 4 5 4
result:
ok single line: '5 4 5 4 4 5 4 4 5 4 '
Test #4:
score: -100
Time Limit Exceeded
input:
1000000 22867 553 901 645 485 940 745 166 365 357 935 102 534 812 329 56 650 100 992 528 829 755 128 190 916 245 942 132 359 367 562 636 77 62 562 404 487 545 298 71 697 784 523 957 383 332 650 636 822 245 379 792 605 239 69 723 867 925 308 511 975 808 341 341 125 940 833 810 282 567 754 893 59 618 ...