Skip to content

Commit

Permalink
adding job changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Aug 18, 2015
1 parent 1a54c61 commit 265d7bd
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 25 deletions.
1 change: 0 additions & 1 deletion LiveArchive/.#i.in

This file was deleted.

40 changes: 23 additions & 17 deletions LiveArchive/Islands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ struct UnionFind {
int unite(int p, int q) {
int i = root(p);
int j = root(q);

if(i == j) return 0;
if(sz[i] < sz[j]) {

if(sz[i] < sz[j]) {
id[i] = j; sz[j] += sz[i];
} else {
id[j] = i; sz[i] += sz[j];
}

return 1;
}
};

int conv(int i, int j) {
return i * N + j;
return i * M + j;
}

int main(void) {
Expand Down Expand Up @@ -91,37 +94,40 @@ int main(void) {
for (int x = 0; x < T; x++) {
cin >> h[x];
}

UnionFind uf(N * M + 1);
UnionFind uf(N * M);
vector<int> ans;

int biggest_reached = INT_MAX;
int component = N * M - 1;
int component = 0;

for (int i = T - 1; i >= 0; i--) {
int curr_h = h[i];
it = lower_bound(val.begin(), val.end(), make_pair(curr_h, make_pair(0, 0)));

if (it != val.end() && it->first < curr_h) it++;

int curr_h = h[i];
it = lower_bound(val.begin(), val.end(), make_pair(curr_h + 1, make_pair(0, 0)));
//cout << curr_h << " " << it->first << "\n";
//if (it != val.end() && it->first < curr_h) it++;
for ( ; it != val.end() && it->first < biggest_reached; it++) {
component += 1;

for (int k = 0; k < 4; k++) {
int pi = it->second.first + dx[k];
int pi = it->second.first + dx[k];
int pj = it->second.second + dy[k];

if (pi >= 0 && pj >= 0 && pi < N && pj < M) {
if (arr[pi][pj] >= curr_h) {
component -= uf.unite(conv(it->second.first, it->second.second), conv(pi, pj));
if (arr[pi][pj] > curr_h) {
if (uf.unite(conv(it->second.first, it->second.second), conv(pi, pj))) {
component -= 1;
}
}
}
}
}

ans.push_back(component);
biggest_reached = curr_h;
biggest_reached = curr_h + 1;
}

for (int i = 0; i < T; i++) {
printf("%d ", N * M - ans[T - i - 1] - 1);
printf("%d ", ans[T - i - 1]);
}
printf("\n");
}
Expand Down
68 changes: 68 additions & 0 deletions LiveArchive/KBroSorting.cpp
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 modified LiveArchive/a.out
Binary file not shown.
14 changes: 7 additions & 7 deletions LiveArchive/i.in
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
13 changes: 13 additions & 0 deletions Notebook/src/FasterSieve.cpp
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];
}

0 comments on commit 265d7bd

Please sign in to comment.