QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#394849 | #1375. TripTik | Zuqa# | WA | 4ms | 3716kb | C++20 | 3.8kb | 2024-04-20 20:32:11 | 2024-04-20 20:32:12 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define el '\n'
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned uint;
typedef __int128 bint;
typedef long double ld;
typedef complex<ld> pt;
typedef unsigned long long ull;
template<typename T, typename X>
using hashTable = gp_hash_table<T, X>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// mt19937_64 for unsigned long long
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 1e5 + 5;
vector<int> pts[N][35];
int d[N][35], vis[N][35];
void doWork()
{
int n, k;
cin >> n >> k;
vector<pair<int, int>> v(n + 1);
for(int i = 1; i <= n; i++)
cin >> v[i].first, v[i].second = i;
v[0] = {0, 0};
sort(v.begin(), v.end());
for(int pw = 0; pw < 30; pw++)
{
int l = 0, r = 0;
set<pair<int, int>, greater<>> st;
st.insert({v[0].second, 0});
for(int i = 0; i < v.size(); i++)
{
while(!(v[l].first >= v[i].first - (1LL << pw) && v[l].first <= v[i].first + (1LL << pw)))
st.erase({v[l].second, l}), l++;
while(r + 1 < n && v[r + 1].first >= v[i].first - (1LL << pw) && v[r + 1].first <= v[i].first + (1LL << pw))
r++, st.insert({v[r].second, r});
auto it = st.begin();
while(pts[i][pw].size() != k && it != st.end())
pts[i][pw].push_back(it->second), it++;
}
}
// for(int i = 0; i < v.size(); i++)
// cout << i << ' ' << v[i].first << ' ' << v[i].second << '\n';
//
// for(int i = 0; i < v.size(); i++)
// {
// for(int pw = 0; pw < 8; pw++)
// {
// cout << v[i].first << ' ' << (1 << pw) << ": ";
// for(auto &it: pts[i][pw])
// cout << v[it].first << ' ';
// cout << '\n';
// }
// }
int src = find(v.begin(), v.end(), make_pair(0, 0)) - v.begin();
queue<pair<int, int>> q;
q.push({src, 0}), vis[src][0] = 1;
while(q.size())
{
int node = q.front().first, zoom = q.front().second;
q.pop();
if(zoom == 0 && !vis[node][33])
{
vis[node][33] = 1;
d[node][33] = d[node][zoom] + 1;
}
if(zoom + 1 < 30 && !vis[node][zoom + 1])
{
vis[node][zoom + 1] = 1;
d[node][zoom + 1] = d[node][zoom] + 1;
q.push({node, zoom + 1});
}
if(zoom - 1 >= 0 && !vis[node][zoom - 1])
{
vis[node][zoom - 1] = 1;
d[node][zoom - 1] = d[node][zoom] + 1;
q.push({node, zoom - 1});
}
for(auto &it: pts[node][zoom])
{
if(!vis[it][zoom])
{
vis[it][zoom] = 1;
d[it][zoom] = d[node][zoom] + 1;
q.push({it, zoom});
}
}
}
vector<int> ans(n + 1);
for(int i = 0; i < v.size(); i++)
{
ans[v[i].second] = INT_MAX;
for(int z = 0; z <= 33; z++)
{
if(vis[i][z] && (std::count(pts[i][z].begin(), pts[i][z].end(), i) || z == 33))
ans[v[i].second] = min(ans[v[i].second], d[i][z]);
}
}
for(int i = 1; i <= n; i++)
cout << (ans[i] == INT_MAX ? -1 : ans[i]) << '\n';
}
signed main()
{
FIO
int T = 1;
// cin >> T;
for(int i = 1; i <= T; i++)
doWork();
}
详细
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 3716kb
input:
4 2 -2 -1 -3 2
output:
3 1 3 -1
result:
wrong answer 4th lines differ - expected: '2', found: '-1'