#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const long long inf = 5e18;
const long double eps = 1e-15L;
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }
ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
int query(int s, int t);
void answer(int i, int a);
void solve(int N) {
int n = N;
int a[N + 1], d[N];
vector<bool> vis(n + 1);
for(int i = 1; i < N; i ++) d[i] = query(i, i + 1);
int l = 2, r = N, posn;
while(l <= r) {
int mid = (l + r) / 2;
if(query(1, mid) == N - 1) r = mid - 1, posn = mid;
else l = mid + 1;
}
a[posn] = N;
a[posn - 1] = N - d[posn - 1];
if(posn + 1 <= N) a[posn + 1] = N - d[posn];
for(int i = posn + 2; i <= N; i ++) {
int c = d[i - 1];
if(c + a[i - 1] > n || vis[c + a[i - 1]]) {
a[i] = a[i - 1] - c;
continue;
}
if(- c + a[i - 1] < 1 || - c + a[i - 1] > n || vis[- c + a[i - 1]]) {
a[i] = a[i - 1] + c;
continue;
}
int b = query(i - 2, i);
if(b + min(a[i - 2], a[i - 1]) == c + a[i - 1]) {
a[i] = c + a[i - 1];
} else if(max(a[i - 2], a[i - 1]) - b == a[i - 1] - c) {
a[i] = a[i - 1] - c;
} else if(a[i - 1] < a[i - 2]) {
a[i] = a[i - 1] + c;
} else a[i] = a[i - 1] - c;
}
for(int i = posn - 2; i >= 1; i --) {
int c = d[i];
if(c + a[i + 1] > n || vis[c + a[i + 1]]) {
a[i] = a[i + 1] - c;
continue;
}
if(- c + a[i + 1] < 1 || - c + a[i + 1] > n || vis[- c + a[i + 1]]) {
a[i] = a[i + 1] + c;
continue;
}
int b = query(i, i + 2);
if(b + min(a[i + 2], a[i + 1]) == c + a[i + 1]) {
a[i] = c + a[i + 1];
} else if(max(a[i + 2], a[i + 1]) - b == a[i + 1] - c) {
a[i] = a[i + 1] - c;
} else if(a[i + 1] < a[i + 2]) {
a[i] = a[i + 1] + c;
} else a[i] = a[i + 1] - c;
}
for(int i = 1; i <= N; i ++) {
// cout<<a[i]<<endl;
answer(i, a[i]);
}
}
Compilation message
xylophone.cpp: In function 'void Freopen(std::string)':
xylophone.cpp:34:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:34:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:52:44: warning: 'posn' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | if(posn + 1 <= N) a[posn + 1] = N - d[posn];
| ~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
4 ms |
436 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
5 ms |
436 KB |
Output is correct |
22 |
Correct |
6 ms |
444 KB |
Output is correct |
23 |
Correct |
7 ms |
440 KB |
Output is correct |
24 |
Correct |
6 ms |
596 KB |
Output is correct |
25 |
Correct |
6 ms |
444 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
7 ms |
440 KB |
Output is correct |
28 |
Correct |
7 ms |
444 KB |
Output is correct |
29 |
Correct |
7 ms |
436 KB |
Output is correct |
30 |
Correct |
6 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
17 |
Correct |
4 ms |
436 KB |
Output is correct |
18 |
Correct |
5 ms |
344 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
5 ms |
436 KB |
Output is correct |
22 |
Correct |
6 ms |
444 KB |
Output is correct |
23 |
Correct |
7 ms |
440 KB |
Output is correct |
24 |
Correct |
6 ms |
596 KB |
Output is correct |
25 |
Correct |
6 ms |
444 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
7 ms |
440 KB |
Output is correct |
28 |
Correct |
7 ms |
444 KB |
Output is correct |
29 |
Correct |
7 ms |
436 KB |
Output is correct |
30 |
Correct |
6 ms |
440 KB |
Output is correct |
31 |
Correct |
11 ms |
452 KB |
Output is correct |
32 |
Correct |
18 ms |
444 KB |
Output is correct |
33 |
Correct |
36 ms |
444 KB |
Output is correct |
34 |
Correct |
33 ms |
540 KB |
Output is correct |
35 |
Correct |
35 ms |
464 KB |
Output is correct |
36 |
Incorrect |
44 ms |
344 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |