QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346137#7949. K-Lotterytuanlinh123TL 1364ms138240kbC++202.5kb2024-03-07 21:02:532024-03-07 21:02:53

Judging History

你现在查看的是最新测评结果

  • [2024-03-07 21:02:53]
  • 评测
  • 测评结果:TL
  • 用时:1364ms
  • 内存:138240kb
  • [2024-03-07 21:02:53]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#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 ll base=41597, Mod=100000004987;
ll po[1000005], a[1000005];
map <ll, int> trace;
vector <int> tick[1005];

namespace SegTree
{
    struct Node
    {
        int cnt=0;
        ll val=0;
        Node(){}
        Node(int x): cnt(!!x), val(x){}
        Node operator + (const Node &a) const
        {
            Node ans;
            ans.cnt=cnt+a.cnt;
            ans.val=(val+(__int128_t)1*a.val*po[cnt])%Mod;
            return ans;
        }
    };

    int n;
    Node St[4000005];
    void init(int sz) {n=sz;}

    void update(int i, int Start, int End, int idx, int val)
    {
        if (Start==End) {St[i]=Node(val); return;}
        int mid=(Start+End)/2;
        if (idx<=mid) update(i*2, Start, mid, idx, val);
        else update(i*2+1, mid+1, End, idx, val); 
        St[i]=St[i*2]+St[i*2+1];
    }

    void update(int idx, int val) {update(1, 1, n, idx, val);}
    ll query() {return St[1].val;}
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int k, m, n; cin >> k >> m >> n;
    long long sum=0; 
    for (int i=0; i<=n; i++)
    {
        po[i]=i?po[i-1]*base%Mod:1;
        if (i<k) sum=(sum+po[i])%Mod;
    }
    for (int i=1; i<=m; i++)
    {
        tick[i].resize(k);
        vector <pair<int, int>> num;
        for (int j=0; j<k; j++)
            cin >> tick[i][j], num.pb({tick[i][j], j+1});
        sort(num.begin(), num.end());
        ll val=0;
        for (int j=0; j<k; j++)
            val=(val+(__int128_t)1*po[j]*num[j].se)%Mod;
        trace[val]=i;
    }
    vector <int> num;
    for (int 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 (int 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)
        {
            ll val=(SegTree::query()-sum*(i-k)%Mod+Mod)%Mod;
            if (trace[val])
            {
                int id=trace[val];
                for (int j:tick[id]) cout << j << " ";
                exit(0);
            }
            SegTree::update(a[i-k+1], 0);
        }   
    }
    cout << 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 68032kb

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: 4ms
memory: 67520kb

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: 4ms
memory: 66276kb

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: 1364ms
memory: 138240kb

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...

output:


result: