QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346076 | #7949. K-Lottery | tuanlinh123 | TL | 1726ms | 216892kb | C++20 | 2.5kb | 2024-03-07 20:12:01 | 2024-03-07 20:12:01 |
Judging History
answer
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
const __int128_t base=41597, Mod=100000004987;
__int128_t po[1000005];
ll a[1000005];
map <__int128_t, ll> trace;
vector <ll> tick[1005];
namespace SegTree
{
struct Node
{
ll cnt=0;
__int128_t val=0;
Node(){}
Node(ll x): cnt(!!x), val(x){}
Node operator + (const Node &a) const
{
Node ans;
ans.cnt=cnt+a.cnt;
ans.val=(val+a.val*po[cnt])%Mod;
return ans;
}
};
ll n;
vector <Node> St;
void init(ll sz) {n=sz, St.resize(n*4+1);}
void update(ll i, ll Start, ll End, ll idx, ll val)
{
if (Start>idx || End<idx) return;
if (Start==End) {St[i]=Node(val); return;}
ll mid=(Start+End)/2;
if (idx<=mid) update(i*2, Start, mid, idx, val);
if (mid+1<=idx) update(i*2+1, mid+1, End, idx, val);
St[i]=St[i*2]+St[i*2+1];
}
void update(ll idx, ll val) {update(1, 1, n, idx, val);}
__int128_t query() {return St[1].val;}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll k, m, n; cin >> k >> m >> n;
__int128_t sum=0;
for (ll i=0; i<=n; i++)
{
po[i]=i?po[i-1]*base%Mod:1;
if (i<k) sum=(sum+po[i])%Mod;
}
for (ll i=1; i<=m; i++)
{
tick[i].resize(k);
vector <pll> num;
for (ll j=0; j<k; j++)
cin >> tick[i][j], num.pb({tick[i][j], j+1});
sort(num.begin(), num.end());
__int128_t val=0;
for (ll j=0; j<k; j++)
val=(val+po[j]*num[j].se)%Mod;
trace[val]=i;
}
vector <ll> num;
for (ll i=1; i<=n; i++) cin >> a[i], num.pb(a[i]);
sort(num.begin(), num.end());
num.resize(unique(num.begin(), num.end())-num.begin());
SegTree::init(n);
for (ll i=1; i<=n; i++)
{
a[i]=lower_bound(num.begin(), num.end(), a[i])-num.begin()+1;
SegTree::update(a[i], i);
if (i>=k)
{
__int128_t val=(SegTree::query()-sum*(i-k)%Mod+Mod)%Mod;
if (trace[val])
{
ll id=trace[val];
for (ll j:tick[id]) cout << j << " ";
exit(0);
}
SegTree::update(a[i-k+1], 0);
}
}
cout << 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
3 2 10 1 2 3 1 3 2 20 35 10 7 99 53 72 33 88 16
output:
1 3 2
result:
ok single line: '1 3 2 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 5 10 1 2 3 4 1 2 4 3 3 4 1 2 4 1 2 3 4 2 3 1 19 31 9 1 89 48 63 30 78 12
output:
4 2 3 1
result:
ok single line: '4 2 3 1 '
Test #3:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
3 3 7 1 3 2 2 3 1 2 1 3 11 22 33 44 55 66 77
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1726ms
memory: 216892kb
input:
10000 10 1000000 1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5...
output:
1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5037 38 5038 39 50...
result:
ok single line: '1 5001 2 5002 3 5003 4 5004 5 ...4998 9998 4999 9999 5000 10000 '
Test #5:
score: -100
Time Limit Exceeded
input:
10000 10 1000000 7171 4541 8189 3253 6694 2078 7384 1786 7847 5040 953 4126 4806 3532 7875 8531 3543 2706 8565 1509 2092 4125 6110 5251 6314 4574 6726 8900 9328 8639 3990 5234 9012 5023 3289 2825 8038 3593 2249 337 6252 3831 7967 3839 2815 540 3754 1009 8772 2939 2845 5067 6587 2615 375 7252 9940 18...