Submission #267039

# Submission time Handle Problem Language Result Execution time Memory
267039 2020-08-15T17:49:32 Z kimbj0709 Cryptography (NOI20_crypto) C++14
100 / 100
306 ms 20176 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 300050
#define mod 1000000007
vector<int> seg(maxn*4,0);
void build(int node,int start,int end){
    if(start==end){
        seg[node] = 1;
        return;
    }
    int mid = (start+end)/2;
    build(node*2+1,start,mid);
    build(node*2+2,mid+1,end);
    seg[node] = seg[node*2+1]+seg[node*2+2];
    return;
}
void update(int node,int start,int end,int pos){
    if(start==end&&start==pos){
        seg[node]--;
        return;
    }
    int mid = (start+end)/2;
    if(pos<=mid){
        update(node*2+1,start,mid,pos);
    }
    else{
        update(node*2+2,mid+1,end,pos);
    }
    seg[node] = seg[node*2+1]+seg[node*2+2];
}
int query(int node,int start,int end,int rangemin,int rangemax){
    if(start>rangemax||end<rangemin){
        return 0;
    }
    if(start>=rangemin&&end<=rangemax){
        return seg[node];
    }
    int mid = (start+end)/2;
    return query(node*2+1,start,mid,rangemin,rangemax)+query(node*2+2,mid+1,end,rangemin,rangemax);
}
int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int no_of_input;
    vector<int> vect1;
    vector<int> vect2;
    int input;
    cin >> no_of_input;
    for(int i=0;i<no_of_input;i++){
        cin >> input;
        vect1.push_back(input);
        vect2.push_back(input);
    }
    sort(vect2.begin(),vect2.end());
    build(0,0,vect1.size()-1);
    /*for(auto k:vect2){
        cout << k << " ";
    }
    cout << "--\n";*/
    for(int i=0;i<vect1.size();i++){
        int temp = vect1[i];
        vect1[i] = lower_bound(vect2.begin(),vect2.end(),temp)-vect2.begin();
    }
    vector<int> fact(maxn,0);
    fact[1] = 1;
    for(int i=2;i<fact.size();i++){
        fact[i] = fact[i-1]*i;
        fact[i] %= mod;
    }
    int sum = 0;
    for(int i=0;i<vect1.size();i++){
        int currsmaller = 0;
        if(vect1[i]!=0){
            currsmaller = query(0,0,vect1.size()-1,0,vect1[i]-1);
        }
        sum += fact[no_of_input-i-1]*currsmaller;
        sum %= mod;
        update(0,0,vect1.size()-1,vect1[i]);
    }
    sum++;
    sum %= mod;
    cout << sum;
}

Compilation message

Crypto.cpp: In function 'int32_t main()':
Crypto.cpp:62:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0;i<vect1.size();i++){
      |                 ~^~~~~~~~~~~~~
Crypto.cpp:68:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i=2;i<fact.size();i++){
      |                 ~^~~~~~~~~~~~
Crypto.cpp:73:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i=0;i<vect1.size();i++){
      |                 ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 8 ms 12032 KB Output is correct
4 Correct 8 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 8 ms 12032 KB Output is correct
7 Correct 8 ms 12160 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 10 ms 12160 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 9 ms 12096 KB Output is correct
12 Correct 9 ms 12032 KB Output is correct
13 Correct 8 ms 12032 KB Output is correct
14 Correct 8 ms 12160 KB Output is correct
15 Correct 8 ms 12032 KB Output is correct
16 Correct 8 ms 12032 KB Output is correct
17 Correct 8 ms 12032 KB Output is correct
18 Correct 8 ms 12032 KB Output is correct
19 Correct 8 ms 12032 KB Output is correct
20 Correct 8 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
22 Correct 8 ms 12032 KB Output is correct
23 Correct 8 ms 12032 KB Output is correct
24 Correct 8 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 164 ms 20020 KB Output is correct
3 Correct 163 ms 20048 KB Output is correct
4 Correct 164 ms 20048 KB Output is correct
5 Correct 164 ms 20040 KB Output is correct
6 Correct 163 ms 19920 KB Output is correct
7 Correct 167 ms 20048 KB Output is correct
8 Correct 162 ms 19924 KB Output is correct
9 Correct 165 ms 20048 KB Output is correct
10 Correct 162 ms 19916 KB Output is correct
11 Correct 161 ms 19912 KB Output is correct
12 Correct 164 ms 19920 KB Output is correct
13 Correct 161 ms 20088 KB Output is correct
14 Correct 165 ms 19920 KB Output is correct
15 Correct 164 ms 19980 KB Output is correct
16 Correct 174 ms 19912 KB Output is correct
17 Correct 174 ms 19920 KB Output is correct
18 Correct 164 ms 19912 KB Output is correct
19 Correct 165 ms 19920 KB Output is correct
20 Correct 176 ms 20048 KB Output is correct
21 Correct 179 ms 19920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 156 ms 19024 KB Output is correct
3 Correct 172 ms 19200 KB Output is correct
4 Correct 157 ms 18896 KB Output is correct
5 Correct 158 ms 18896 KB Output is correct
6 Correct 168 ms 19064 KB Output is correct
7 Correct 155 ms 19060 KB Output is correct
8 Correct 160 ms 18896 KB Output is correct
9 Correct 157 ms 18976 KB Output is correct
10 Correct 158 ms 19016 KB Output is correct
11 Correct 155 ms 19016 KB Output is correct
12 Correct 156 ms 18900 KB Output is correct
13 Correct 155 ms 19064 KB Output is correct
14 Correct 167 ms 19024 KB Output is correct
15 Correct 167 ms 19016 KB Output is correct
16 Correct 173 ms 19152 KB Output is correct
17 Correct 158 ms 19020 KB Output is correct
18 Correct 161 ms 19016 KB Output is correct
19 Correct 168 ms 19144 KB Output is correct
20 Correct 156 ms 19024 KB Output is correct
21 Correct 157 ms 19016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12160 KB Output is correct
2 Correct 10 ms 12160 KB Output is correct
3 Correct 10 ms 12160 KB Output is correct
4 Correct 10 ms 12160 KB Output is correct
5 Correct 13 ms 12160 KB Output is correct
6 Correct 11 ms 12160 KB Output is correct
7 Correct 10 ms 12192 KB Output is correct
8 Correct 10 ms 12160 KB Output is correct
9 Correct 10 ms 12160 KB Output is correct
10 Correct 10 ms 12160 KB Output is correct
11 Correct 11 ms 12160 KB Output is correct
12 Correct 10 ms 12160 KB Output is correct
13 Correct 10 ms 12160 KB Output is correct
14 Correct 10 ms 12160 KB Output is correct
15 Correct 8 ms 12032 KB Output is correct
16 Correct 12 ms 12160 KB Output is correct
17 Correct 11 ms 12160 KB Output is correct
18 Correct 10 ms 12160 KB Output is correct
19 Correct 11 ms 12160 KB Output is correct
20 Correct 10 ms 12160 KB Output is correct
21 Correct 10 ms 12160 KB Output is correct
22 Correct 10 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 8 ms 12032 KB Output is correct
4 Correct 8 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 8 ms 12032 KB Output is correct
7 Correct 8 ms 12160 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 10 ms 12160 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 9 ms 12096 KB Output is correct
12 Correct 9 ms 12032 KB Output is correct
13 Correct 8 ms 12032 KB Output is correct
14 Correct 8 ms 12160 KB Output is correct
15 Correct 8 ms 12032 KB Output is correct
16 Correct 8 ms 12032 KB Output is correct
17 Correct 8 ms 12032 KB Output is correct
18 Correct 8 ms 12032 KB Output is correct
19 Correct 8 ms 12032 KB Output is correct
20 Correct 8 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
22 Correct 8 ms 12032 KB Output is correct
23 Correct 8 ms 12032 KB Output is correct
24 Correct 8 ms 12032 KB Output is correct
25 Correct 9 ms 12160 KB Output is correct
26 Correct 10 ms 12160 KB Output is correct
27 Correct 10 ms 12160 KB Output is correct
28 Correct 10 ms 12160 KB Output is correct
29 Correct 13 ms 12160 KB Output is correct
30 Correct 11 ms 12160 KB Output is correct
31 Correct 10 ms 12192 KB Output is correct
32 Correct 10 ms 12160 KB Output is correct
33 Correct 10 ms 12160 KB Output is correct
34 Correct 10 ms 12160 KB Output is correct
35 Correct 11 ms 12160 KB Output is correct
36 Correct 10 ms 12160 KB Output is correct
37 Correct 10 ms 12160 KB Output is correct
38 Correct 10 ms 12160 KB Output is correct
39 Correct 8 ms 12032 KB Output is correct
40 Correct 12 ms 12160 KB Output is correct
41 Correct 11 ms 12160 KB Output is correct
42 Correct 10 ms 12160 KB Output is correct
43 Correct 11 ms 12160 KB Output is correct
44 Correct 10 ms 12160 KB Output is correct
45 Correct 10 ms 12160 KB Output is correct
46 Correct 10 ms 12160 KB Output is correct
47 Correct 10 ms 12160 KB Output is correct
48 Correct 12 ms 12160 KB Output is correct
49 Correct 11 ms 12160 KB Output is correct
50 Correct 11 ms 12288 KB Output is correct
51 Correct 10 ms 12160 KB Output is correct
52 Correct 10 ms 12288 KB Output is correct
53 Correct 10 ms 12160 KB Output is correct
54 Correct 10 ms 12160 KB Output is correct
55 Correct 10 ms 12160 KB Output is correct
56 Correct 10 ms 12160 KB Output is correct
57 Correct 10 ms 12160 KB Output is correct
58 Correct 10 ms 12160 KB Output is correct
59 Correct 10 ms 12160 KB Output is correct
60 Correct 11 ms 12160 KB Output is correct
61 Correct 8 ms 12160 KB Output is correct
62 Correct 10 ms 12160 KB Output is correct
63 Correct 10 ms 12160 KB Output is correct
64 Correct 10 ms 12160 KB Output is correct
65 Correct 10 ms 12160 KB Output is correct
66 Correct 10 ms 12160 KB Output is correct
67 Correct 10 ms 12160 KB Output is correct
68 Correct 10 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 156 ms 19024 KB Output is correct
3 Correct 172 ms 19200 KB Output is correct
4 Correct 157 ms 18896 KB Output is correct
5 Correct 158 ms 18896 KB Output is correct
6 Correct 168 ms 19064 KB Output is correct
7 Correct 155 ms 19060 KB Output is correct
8 Correct 160 ms 18896 KB Output is correct
9 Correct 157 ms 18976 KB Output is correct
10 Correct 158 ms 19016 KB Output is correct
11 Correct 155 ms 19016 KB Output is correct
12 Correct 156 ms 18900 KB Output is correct
13 Correct 155 ms 19064 KB Output is correct
14 Correct 167 ms 19024 KB Output is correct
15 Correct 167 ms 19016 KB Output is correct
16 Correct 173 ms 19152 KB Output is correct
17 Correct 158 ms 19020 KB Output is correct
18 Correct 161 ms 19016 KB Output is correct
19 Correct 168 ms 19144 KB Output is correct
20 Correct 156 ms 19024 KB Output is correct
21 Correct 157 ms 19016 KB Output is correct
22 Correct 9 ms 12160 KB Output is correct
23 Correct 10 ms 12160 KB Output is correct
24 Correct 10 ms 12160 KB Output is correct
25 Correct 10 ms 12160 KB Output is correct
26 Correct 13 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 10 ms 12192 KB Output is correct
29 Correct 10 ms 12160 KB Output is correct
30 Correct 10 ms 12160 KB Output is correct
31 Correct 10 ms 12160 KB Output is correct
32 Correct 11 ms 12160 KB Output is correct
33 Correct 10 ms 12160 KB Output is correct
34 Correct 10 ms 12160 KB Output is correct
35 Correct 10 ms 12160 KB Output is correct
36 Correct 8 ms 12032 KB Output is correct
37 Correct 12 ms 12160 KB Output is correct
38 Correct 11 ms 12160 KB Output is correct
39 Correct 10 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 10 ms 12160 KB Output is correct
42 Correct 10 ms 12160 KB Output is correct
43 Correct 10 ms 12160 KB Output is correct
44 Correct 8 ms 12160 KB Output is correct
45 Correct 287 ms 18896 KB Output is correct
46 Correct 282 ms 19016 KB Output is correct
47 Correct 282 ms 18896 KB Output is correct
48 Correct 277 ms 19152 KB Output is correct
49 Correct 271 ms 18896 KB Output is correct
50 Correct 267 ms 18896 KB Output is correct
51 Correct 274 ms 19072 KB Output is correct
52 Correct 271 ms 19016 KB Output is correct
53 Correct 276 ms 19024 KB Output is correct
54 Correct 273 ms 18896 KB Output is correct
55 Correct 291 ms 19024 KB Output is correct
56 Correct 284 ms 18896 KB Output is correct
57 Correct 284 ms 19024 KB Output is correct
58 Correct 8 ms 12032 KB Output is correct
59 Correct 291 ms 19024 KB Output is correct
60 Correct 287 ms 18896 KB Output is correct
61 Correct 298 ms 19144 KB Output is correct
62 Correct 280 ms 19024 KB Output is correct
63 Correct 282 ms 18896 KB Output is correct
64 Correct 276 ms 18980 KB Output is correct
65 Correct 274 ms 19024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 8 ms 12032 KB Output is correct
4 Correct 8 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 8 ms 12032 KB Output is correct
7 Correct 8 ms 12160 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 10 ms 12160 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 9 ms 12096 KB Output is correct
12 Correct 9 ms 12032 KB Output is correct
13 Correct 8 ms 12032 KB Output is correct
14 Correct 8 ms 12160 KB Output is correct
15 Correct 8 ms 12032 KB Output is correct
16 Correct 8 ms 12032 KB Output is correct
17 Correct 8 ms 12032 KB Output is correct
18 Correct 8 ms 12032 KB Output is correct
19 Correct 8 ms 12032 KB Output is correct
20 Correct 8 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
22 Correct 8 ms 12032 KB Output is correct
23 Correct 8 ms 12032 KB Output is correct
24 Correct 8 ms 12032 KB Output is correct
25 Correct 8 ms 12032 KB Output is correct
26 Correct 164 ms 20020 KB Output is correct
27 Correct 163 ms 20048 KB Output is correct
28 Correct 164 ms 20048 KB Output is correct
29 Correct 164 ms 20040 KB Output is correct
30 Correct 163 ms 19920 KB Output is correct
31 Correct 167 ms 20048 KB Output is correct
32 Correct 162 ms 19924 KB Output is correct
33 Correct 165 ms 20048 KB Output is correct
34 Correct 162 ms 19916 KB Output is correct
35 Correct 161 ms 19912 KB Output is correct
36 Correct 164 ms 19920 KB Output is correct
37 Correct 161 ms 20088 KB Output is correct
38 Correct 165 ms 19920 KB Output is correct
39 Correct 164 ms 19980 KB Output is correct
40 Correct 174 ms 19912 KB Output is correct
41 Correct 174 ms 19920 KB Output is correct
42 Correct 164 ms 19912 KB Output is correct
43 Correct 165 ms 19920 KB Output is correct
44 Correct 176 ms 20048 KB Output is correct
45 Correct 179 ms 19920 KB Output is correct
46 Correct 9 ms 12032 KB Output is correct
47 Correct 156 ms 19024 KB Output is correct
48 Correct 172 ms 19200 KB Output is correct
49 Correct 157 ms 18896 KB Output is correct
50 Correct 158 ms 18896 KB Output is correct
51 Correct 168 ms 19064 KB Output is correct
52 Correct 155 ms 19060 KB Output is correct
53 Correct 160 ms 18896 KB Output is correct
54 Correct 157 ms 18976 KB Output is correct
55 Correct 158 ms 19016 KB Output is correct
56 Correct 155 ms 19016 KB Output is correct
57 Correct 156 ms 18900 KB Output is correct
58 Correct 155 ms 19064 KB Output is correct
59 Correct 167 ms 19024 KB Output is correct
60 Correct 167 ms 19016 KB Output is correct
61 Correct 173 ms 19152 KB Output is correct
62 Correct 158 ms 19020 KB Output is correct
63 Correct 161 ms 19016 KB Output is correct
64 Correct 168 ms 19144 KB Output is correct
65 Correct 156 ms 19024 KB Output is correct
66 Correct 157 ms 19016 KB Output is correct
67 Correct 9 ms 12160 KB Output is correct
68 Correct 10 ms 12160 KB Output is correct
69 Correct 10 ms 12160 KB Output is correct
70 Correct 10 ms 12160 KB Output is correct
71 Correct 13 ms 12160 KB Output is correct
72 Correct 11 ms 12160 KB Output is correct
73 Correct 10 ms 12192 KB Output is correct
74 Correct 10 ms 12160 KB Output is correct
75 Correct 10 ms 12160 KB Output is correct
76 Correct 10 ms 12160 KB Output is correct
77 Correct 11 ms 12160 KB Output is correct
78 Correct 10 ms 12160 KB Output is correct
79 Correct 10 ms 12160 KB Output is correct
80 Correct 10 ms 12160 KB Output is correct
81 Correct 8 ms 12032 KB Output is correct
82 Correct 12 ms 12160 KB Output is correct
83 Correct 11 ms 12160 KB Output is correct
84 Correct 10 ms 12160 KB Output is correct
85 Correct 11 ms 12160 KB Output is correct
86 Correct 10 ms 12160 KB Output is correct
87 Correct 10 ms 12160 KB Output is correct
88 Correct 10 ms 12160 KB Output is correct
89 Correct 10 ms 12160 KB Output is correct
90 Correct 12 ms 12160 KB Output is correct
91 Correct 11 ms 12160 KB Output is correct
92 Correct 11 ms 12288 KB Output is correct
93 Correct 10 ms 12160 KB Output is correct
94 Correct 10 ms 12288 KB Output is correct
95 Correct 10 ms 12160 KB Output is correct
96 Correct 10 ms 12160 KB Output is correct
97 Correct 10 ms 12160 KB Output is correct
98 Correct 10 ms 12160 KB Output is correct
99 Correct 10 ms 12160 KB Output is correct
100 Correct 10 ms 12160 KB Output is correct
101 Correct 10 ms 12160 KB Output is correct
102 Correct 11 ms 12160 KB Output is correct
103 Correct 8 ms 12160 KB Output is correct
104 Correct 10 ms 12160 KB Output is correct
105 Correct 10 ms 12160 KB Output is correct
106 Correct 10 ms 12160 KB Output is correct
107 Correct 10 ms 12160 KB Output is correct
108 Correct 10 ms 12160 KB Output is correct
109 Correct 10 ms 12160 KB Output is correct
110 Correct 10 ms 12160 KB Output is correct
111 Correct 8 ms 12160 KB Output is correct
112 Correct 287 ms 18896 KB Output is correct
113 Correct 282 ms 19016 KB Output is correct
114 Correct 282 ms 18896 KB Output is correct
115 Correct 277 ms 19152 KB Output is correct
116 Correct 271 ms 18896 KB Output is correct
117 Correct 267 ms 18896 KB Output is correct
118 Correct 274 ms 19072 KB Output is correct
119 Correct 271 ms 19016 KB Output is correct
120 Correct 276 ms 19024 KB Output is correct
121 Correct 273 ms 18896 KB Output is correct
122 Correct 291 ms 19024 KB Output is correct
123 Correct 284 ms 18896 KB Output is correct
124 Correct 284 ms 19024 KB Output is correct
125 Correct 8 ms 12032 KB Output is correct
126 Correct 291 ms 19024 KB Output is correct
127 Correct 287 ms 18896 KB Output is correct
128 Correct 298 ms 19144 KB Output is correct
129 Correct 280 ms 19024 KB Output is correct
130 Correct 282 ms 18896 KB Output is correct
131 Correct 276 ms 18980 KB Output is correct
132 Correct 274 ms 19024 KB Output is correct
133 Correct 8 ms 12032 KB Output is correct
134 Correct 277 ms 19920 KB Output is correct
135 Correct 273 ms 19920 KB Output is correct
136 Correct 281 ms 19980 KB Output is correct
137 Correct 272 ms 19920 KB Output is correct
138 Correct 272 ms 19920 KB Output is correct
139 Correct 288 ms 20076 KB Output is correct
140 Correct 301 ms 20040 KB Output is correct
141 Correct 287 ms 19968 KB Output is correct
142 Correct 280 ms 19920 KB Output is correct
143 Correct 288 ms 19912 KB Output is correct
144 Correct 283 ms 19920 KB Output is correct
145 Correct 288 ms 20048 KB Output is correct
146 Correct 291 ms 19920 KB Output is correct
147 Correct 8 ms 12032 KB Output is correct
148 Correct 305 ms 19920 KB Output is correct
149 Correct 285 ms 19920 KB Output is correct
150 Correct 306 ms 19940 KB Output is correct
151 Correct 300 ms 19912 KB Output is correct
152 Correct 305 ms 20176 KB Output is correct
153 Correct 302 ms 20104 KB Output is correct
154 Correct 284 ms 19920 KB Output is correct