-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aajjbb
committed
Aug 18, 2015
1 parent
1a54c61
commit 265d7bd
Showing
6 changed files
with
111 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <bits/stdc++.h> | ||
|
||
template<typename T> T gcd(T a, T b) { | ||
if(!b) return a; | ||
return gcd(b, a % b); | ||
} | ||
template<typename T> T lcm(T a, T b) { | ||
return a * b / gcd(a, b); | ||
} | ||
|
||
template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; } | ||
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; } | ||
int in() { int x; scanf("%d", &x); return x; } | ||
|
||
using namespace std; | ||
|
||
#ifdef ONLINE_JUDGE | ||
#define debug(args...) | ||
#else | ||
#define debug(args...) fprintf(stderr,args) | ||
#endif | ||
|
||
typedef long long Int; | ||
typedef unsigned uint; | ||
|
||
const int MAXN = 1000005; | ||
|
||
int T, N; | ||
int P[MAXN], tree[MAXN]; | ||
|
||
void add(int pos, int val) { | ||
for (int i = pos; i <= N; i += (i & (-i))) { | ||
tree[i] += val; | ||
} | ||
} | ||
|
||
int sum(int pos) { | ||
int ans = 0; | ||
for (int i = pos; i > 0; i -= (i & (-i))) { | ||
ans += tree[i]; | ||
} | ||
return ans; | ||
} | ||
|
||
int main(void) { | ||
cin >> T; | ||
|
||
for (int t = 1; t <= T; t++) { | ||
cin >> N; | ||
|
||
for (int i = 0; i < N; i++) { | ||
cin >> P[i]; | ||
tree[i] = 0; | ||
} | ||
|
||
int ans = 0; | ||
|
||
for (int i = N - 1; i >= 0; i--) { | ||
if (sum(P[i] - 1)) { | ||
ans += 1; | ||
} | ||
add(P[i], i); | ||
} | ||
|
||
cout << "Case #" << t << ": " << ans << "\n"; | ||
} | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | ||
4 5 | ||
1 2 3 3 1 | ||
1 3 2 2 1 | ||
2 1 3 4 3 | ||
1 2 2 2 2 | ||
1 | ||
2 | ||
4 4 | ||
4 1 3 1 | ||
1 2 2 2 | ||
1 4 5 1 | ||
2 2 2 4 | ||
5 | ||
0 1 2 3 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//O(n) | ||
const int N = 10000000; | ||
int lp[N+1]; | ||
vector<int> pr; | ||
|
||
for (int i=2; i<=N; ++i) { | ||
if (lp[i] == 0) { | ||
lp[i] = i; | ||
pr.push_back (i); | ||
} | ||
for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) | ||
lp[i * pr[j]] = pr[j]; | ||
} |