QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584011#1913. Non-Decreasing Subsequencesmakrav8.333333 201ms14296kbC++203.5kb2024-09-23 03:42:022024-09-23 03:42:03

Judging History

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

  • [2024-09-23 03:42:03]
  • 评测
  • 测评结果:8.333333
  • 用时:201ms
  • 内存:14296kb
  • [2024-09-23 03:42:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

const int mod = 1e9 + 7;

struct fenwick {
    int n;
    vector<int> t;
    fenwick() = default;
    fenwick(int n_) {
        n = n_;
        t.assign(n + 1, 0);
    }

    void clear() {
        t.assign(n + 1, 0);
    }
 
    void upd(int p, int vl) {
        for (; p <= n; p = (p | (p + 1))) {
            t[p] += vl;
            if (t[p] >= mod) t[p] -= mod;
        }
    }
 
    int get(int p) {
        int sm = 0;
        for (; p > 0; p = (p & (p + 1)) - 1) {
            sm += t[p];
            if (sm >= mod) sm -= mod;
        }
        return sm;
    }
};

void solve() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int q; cin >> q;
    vector<vector<pair<int, int>>> qrs(n);
    vector<int> answ(q);
    for (int i = 0; i < q; i++) {
        int l, r; cin >> l >> r;
        l--; r--;
        qrs[l].pb({r, i});
    }
    for (int i = 0; i < n; i++) sort(all(qrs[i]));
    vector<vector<int>> dp(n, vector<int>(k + 1));
    vector<fenwick> fw_right(k + 1), fw_left(k + 1);
    for (int i = 1; i <= k; i++) {
        fw_right[i] = fenwick(k + 2);
        fw_left[i] = fenwick(k + 2);
    }
    auto solve = [&](int l, int r, auto&&self) -> void {
        if (l + 1 == r) {
            for (auto &u : qrs[l]) {
                answ[u.second] = 2;
            }
            qrs[l].clear();
            return;
        }
        int tm = (l + r) / 2;
        for (int i = 1; i <= k; i++) {
            fw_right[i].clear(); fw_left[i].clear();
        }
        for (int i = tm; i < r; i++) {
            for (int j = 1; j <= a[i]; j++) {
                fw_right[j].upd(a[i], fw_right[j].get(a[i]));
                if (j == a[i]) fw_right[j].upd(a[i], 1);
            }
            for (int j = 1; j <= k; j++) dp[i][j] = fw_right[j].get(k);
        }
        for (int i = tm - 1; i >= l; i--) {
            for (int j = a[i]; j <= k; j++) {
                fw_left[j].upd(a[i], (fw_left[j].get(k) - fw_left[j].get(a[i] - 1) + mod) % mod);
                if (j == a[i]) fw_left[j].upd(a[i], 1);
            }
            for (int j = 1; j <= k; j++) dp[i][j] = fw_left[j].get(k);
        }
        for (int i = l; i < tm; i++) {
            while (!qrs[i].empty() && qrs[i].back().first >= tm) {
                int rg = qrs[i].back().first;
                int sm = 0, ans = 1;
                for (int j = 1; j <= k; j++) {
                    ans += dp[rg][j] + dp[i][j];
                    ans %= mod;
                    sm += dp[i][j];
                    if (sm >= mod) sm -= mod;
                    ans += dp[rg][j] * 1ll * sm;
                    ans %= mod;
                }
                answ[qrs[i].back().second] = ans;
                qrs[i].pop_back();
            }
        }

        self(l, tm, self);
        self(tm, r, self);
    };
    solve(0, n, solve);
    for (auto &u : answ) cout << u << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 8.33333
Accepted
time: 0ms
memory: 3544kb

input:

5 2
1 2 1 1 2
3
2 3
4 5
1 5

output:

3
4
20

result:

ok 3 lines

Test #2:

score: 0
Wrong Answer
time: 201ms
memory: 14296kb

input:

50000 20
1 5 20 6 15 5 4 17 6 16 20 13 2 18 17 2 16 12 12 3 1 10 13 1 14 12 14 2 8 2 3 20 7 2 17 13 18 20 9 15 16 20 7 9 18 3 3 5 6 14 7 18 15 19 18 9 2 12 10 10 5 12 1 3 5 18 8 2 9 16 8 16 8 15 17 5 9 19 9 15 12 7 4 7 17 2 15 19 5 16 20 9 19 20 4 3 9 11 16 10 18 3 5 5 17 1 1 18 11 9 4 3 7 7 1 4 20 ...

output:

728899252
582053321
-660810398
-661644656
-671279979
899826729
874050367
551869282
190856737
906879887
-199121329
32388896
902910361
-543931030
196994243
629885443
-66151552
723738365
694919466
-721063422
767580255
192
-456981584
863041161
-999304115
191906846
961066497
-892249597
269196741
-9104974...

result:

wrong answer 1st lines differ - expected: '648477307', found: '728899252'

Test #3:

score: 0
Wrong Answer
time: 194ms
memory: 14268kb

input:

50000 20
12 10 2 6 1 3 11 11 13 20 3 16 20 16 13 18 3 19 18 18 1 15 16 7 9 9 3 9 15 15 20 6 16 13 11 16 15 13 19 19 4 1 7 4 8 11 1 11 9 19 20 9 5 15 7 13 3 9 13 9 15 4 6 11 9 16 18 15 1 16 14 4 8 12 19 16 2 20 6 10 10 17 18 14 11 16 18 6 4 10 14 11 13 20 1 1 7 18 16 19 6 1 15 13 12 13 20 5 4 17 14 5...

output:

103811322
-108642572
251851587
-363721112
882090295
-613778656
132352681
-854416214
988675507
563758061
-849693099
337470343
107397921
-940715815
-141334163
195722319
449664927
-659424875
-703788015
280640001
-786258103
-397452541
-376798883
-791854513
223722730
-781871098
285988986
321152544
-67329...

result:

wrong answer 1st lines differ - expected: '510482945', found: '103811322'

Test #4:

score: 0
Wrong Answer
time: 198ms
memory: 14140kb

input:

50000 20
16 12 3 14 15 20 3 16 13 10 12 10 20 14 17 2 12 8 20 6 7 4 12 15 14 13 5 7 11 3 3 6 6 17 12 20 16 14 16 8 4 19 17 15 4 6 16 15 13 8 12 12 3 4 18 16 8 2 3 18 16 17 4 1 14 15 12 9 20 7 9 3 17 17 10 1 2 17 7 7 4 19 18 6 14 7 14 1 20 8 19 15 4 14 7 9 20 18 10 19 17 10 14 13 6 3 5 20 19 4 6 15 1...

output:

-138309672
133458470
-297346410
355120216
613779714
388201520
-489279428
498857489
-370212271
622387713
481293774
-373656923
485879152
-688263254
-904018667
-774850643
-208627390
-959604473
-314538032
-905560460
973306457
438553197
292647121
207880312
990675796
132285677
607496665
874526022
71942997...

result:

wrong answer 1st lines differ - expected: '637280489', found: '-138309672'

Test #5:

score: 0
Wrong Answer
time: 53ms
memory: 6880kb

input:

1000 20
15 3 13 7 4 11 8 18 3 3 2 18 11 5 15 16 4 19 7 6 11 18 11 11 8 16 13 1 3 12 19 17 6 4 15 10 6 3 19 8 17 20 17 7 16 11 14 20 1 13 5 11 10 7 14 9 2 6 10 4 9 20 12 15 15 7 16 20 9 14 19 17 6 15 3 1 18 9 20 10 13 4 1 2 3 14 11 4 11 12 20 19 3 3 13 18 9 8 9 9 14 8 5 19 14 20 11 3 20 11 13 12 6 5 ...

output:

664451093
745937938
747457634
309327725
-443185069
395324111
404575094
76786153
-923538324
311972667
89366867
632909367
19667
279452563
912731625
497110043
724283422
449417778
-54043523
770222865
298838703
58739375
23162408
607509701
251235068
1622167
7827678
879533021
954154912
577005114
742538286
...

result:

wrong answer 1st lines differ - expected: '555039665', found: '664451093'

Test #6:

score: 0
Wrong Answer
time: 54ms
memory: 6828kb

input:

1000 20
4 5 7 12 5 3 1 4 18 6 4 6 15 14 12 10 17 3 15 16 2 20 9 6 11 1 17 16 20 20 2 15 17 20 18 13 14 11 8 11 16 12 16 3 17 19 4 14 13 19 9 6 10 9 12 12 1 20 8 13 11 1 19 19 20 17 4 5 19 11 16 6 14 3 8 11 14 12 16 18 2 16 4 3 5 7 14 17 6 13 9 8 13 8 7 4 16 10 9 6 12 16 11 6 10 11 8 3 14 3 1 15 18 4...

output:

894800271
-149121387
-237060785
-228787866
877745774
60579366
609300972
676
-571541638
35910130
-227722080
-521595457
124
-1197448
952485909
169702
-421213667
51335488
-216908982
-835805021
410195021
75206219
803974887
91205418
24210
60646
427
386514906
-597827133
-734812435
-146867264
4048
-7429605...

result:

wrong answer 1st lines differ - expected: '819635573', found: '894800271'

Test #7:

score: 0
Wrong Answer
time: 88ms
memory: 10764kb

input:

50000 5
5 5 1 4 4 4 2 3 3 1 1 1 4 2 2 2 5 5 5 4 4 4 4 1 4 3 2 1 5 1 1 4 2 1 4 1 1 5 5 3 2 1 5 2 4 3 4 5 3 3 3 1 3 3 3 1 5 5 4 4 2 1 4 4 1 4 1 3 1 5 1 2 2 2 4 5 5 2 2 2 1 1 4 3 4 2 1 3 3 1 4 1 1 4 1 3 3 1 5 3 3 2 1 4 4 4 1 5 2 2 3 4 2 3 2 2 1 4 5 3 4 5 1 1 3 1 3 2 4 4 1 3 3 2 1 1 2 3 2 1 1 4 4 5 1 2 ...

output:

-804134616
-449650236
240845682
165895250
112222060
285319182
565875832
-779748599
-402199072
-591072489
276606329
439891874
-944194319
-420202344
278589524
832041692
-853243548
555419448
-111839213
-50485964
-926285913
-43532084
861814243
-579754952
-944974351
-99973882
871007384
181940124
91705507...

result:

wrong answer 1st lines differ - expected: '926368451', found: '-804134616'

Test #8:

score: 0
Wrong Answer
time: 85ms
memory: 10696kb

input:

50000 5
4 4 5 3 5 1 3 1 4 3 4 4 5 5 5 5 4 2 3 2 3 2 3 2 4 3 2 4 5 1 3 5 1 3 3 5 5 2 2 3 1 2 1 3 4 3 2 2 4 1 3 1 2 2 2 5 5 5 1 1 2 3 1 2 2 5 4 3 3 2 3 1 1 5 3 4 2 1 5 2 3 4 4 1 5 5 3 1 2 3 2 3 2 4 2 1 5 5 3 2 3 5 2 3 5 1 1 1 3 2 3 5 5 1 3 2 3 5 2 1 2 3 5 5 3 1 5 2 2 3 4 5 4 2 2 3 5 5 1 2 1 3 4 3 5 1 ...

output:

878728318
-46287490
306903276
-265092851
-238136839
107547545
-288249233
943727254
586962994
72052644
402854487
37809963
-450541564
706715894
-203525261
-111268694
848116055
-865811862
-387575082
-241789031
-713567431
-591899871
422852385
-22361300
-940644192
157565013
-568138937
-45924712
-42300235...

result:

wrong answer 1st lines differ - expected: '125103175', found: '878728318'

Test #9:

score: 0
Wrong Answer
time: 85ms
memory: 10836kb

input:

50000 5
3 5 4 1 5 5 3 3 2 4 2 3 2 2 5 1 2 4 2 3 2 5 4 3 5 3 2 4 1 1 4 5 2 3 2 3 2 5 1 3 5 4 2 1 5 2 3 3 5 4 1 3 5 1 5 4 5 1 2 5 3 3 2 1 5 5 4 1 4 4 4 5 4 5 2 1 1 4 3 2 4 5 4 3 2 3 4 2 1 2 3 3 4 4 4 3 4 4 4 4 2 4 1 2 5 2 2 1 3 2 4 1 1 3 1 5 2 4 1 2 2 3 2 1 4 2 3 4 5 3 4 3 3 1 4 3 5 1 3 2 4 3 4 1 5 4 ...

output:

63928804
692539161
811982755
-711014737
223522155
328246949
-58439631
-437030706
-319430276
-85234659
949611723
572329466
313894449
569080999
196947821
684316441
167449120
-624832446
537550005
-225607047
-481745040
888654960
403499794
415074472
481392459
535123904
-988371754
-438958961
964013405
608...

result:

wrong answer 1st lines differ - expected: '338257176', found: '63928804'

Test #10:

score: 0
Wrong Answer
time: 158ms
memory: 12292kb

input:

50000 20
16 13 12 19 15 8 19 11 4 15 20 20 14 10 16 4 6 6 17 5 7 5 16 16 5 14 13 6 6 5 10 1 9 2 12 3 1 10 5 16 16 16 15 9 5 2 12 2 19 20 6 5 17 13 20 1 18 4 7 4 8 8 16 16 1 19 10 1 20 14 16 16 9 10 16 5 3 8 6 1 19 4 5 15 8 17 8 6 20 14 1 8 13 8 15 14 7 17 14 18 2 10 13 11 11 1 7 14 20 5 14 18 8 19 5...

output:

-643683920
-910181053
297284883
267372295
-679279219
869288642
-819454747
-556002429
-877211278
253685778
791825957
-875153154
110839974
-308164886
-779012615
57462455
436962619
389682
603972916
814461417
418940966
-857021209
270621940
-347581430
-209172789
248540783
280
-415513899
-17891968
-259784...

result:

wrong answer 1st lines differ - expected: '247419772', found: '-643683920'

Test #11:

score: 0
Wrong Answer
time: 157ms
memory: 12308kb

input:

50000 20
1 6 13 1 6 5 16 8 4 17 18 15 5 18 15 12 14 2 18 13 13 17 9 15 3 19 15 15 2 16 11 14 13 15 6 18 11 1 5 14 17 14 8 14 4 14 5 9 16 14 2 8 11 2 14 5 1 1 19 2 16 1 7 8 15 12 17 5 13 13 10 1 6 18 14 1 3 11 10 18 4 3 17 6 4 11 2 4 11 12 17 18 12 3 17 18 7 13 14 11 5 4 11 2 13 17 15 15 19 4 5 2 6 1...

output:

-421489164
-379942367
750889626
959332563
-782620784
655899119
-28222731
781802308
488106434
-6757108
34664323
-458310954
-466384090
-73263652
-385951204
92308431
752516721
-46676335
724873753
573891670
-339150172
313482156
-695483619
441697774
602356718
244577867
-261101803
-158030391
658578056
-27...

result:

wrong answer 1st lines differ - expected: '181383728', found: '-421489164'

Test #12:

score: 0
Wrong Answer
time: 158ms
memory: 12312kb

input:

50000 20
14 1 16 11 11 6 19 10 20 4 17 3 13 19 13 11 4 18 16 17 16 1 18 16 18 6 13 2 4 15 19 17 15 15 20 6 12 10 7 3 5 3 5 17 2 18 19 5 7 14 1 3 14 10 10 3 16 14 5 19 8 3 7 3 9 18 20 12 7 6 15 11 9 11 19 2 20 18 6 7 3 18 1 17 7 2 19 14 16 15 12 15 10 11 9 18 8 8 2 7 14 16 9 14 6 8 15 18 17 12 16 19 ...

output:

-37686952
-230306783
-540331570
-969738828
-169961505
624355293
234449514
-54743856
-105571041
114164420
-894342487
-238084905
-114249314
236593049
122613104
-9140527
-710304784
318722064
-176307339
-478156700
-227103236
624560795
953757653
-110632204
-157271784
804954292
937516503
-172881952
551125...

result:

wrong answer 1st lines differ - expected: '921338517', found: '-37686952'