Блог пользователя warlock

Автор warlock, 10 лет назад, По-английски

Why did TopCoder removed posts from their cookbook. It was more helpful than their tutorials are.

Topcoder CookBook

Or am I missing something!!

Полный текст и комментарии »

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

Автор warlock, 10 лет назад, По-английски

Who is vjudge[1-5] anyway. Is He/She/IT(bot) trying to flood Codeforces Servers.

ProblemSet Status is full of submissions from vjudge[1-5]. o.O

vjudge1, vjudge2, vjudge3, vjudge4, vjudge5

Полный текст и комментарии »

  • Проголосовать: нравится
  • -32
  • Проголосовать: не нравится

Автор warlock, 10 лет назад, По-английски

Recently I saw a code which was accessing the index of a vector equal to its size. The Line read

for (int i = 0; i <= nums.size(); i++) {
	max_cost[i][i] = min_cost[i][i] = nums[i];
}

The code is for the Spoj Question Pocket Money. Whole Code link.

As per my knowledge this should give segmentation fault instead the solution gets accepted. Please can someone tell me what is happening here, why it doesn't give segmentation fault!

Полный текст и комментарии »

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

Автор warlock, 10 лет назад, По-английски

Hi,

I have been trying to solve GSS1 on Spoj and its giving me segmentation fault. I am not able to figure out whats the problem. Below is my code, please see if you can figure out whats the problem.

http://www.spoj.com/problems/GSS1/


#include <iostream> #include <algorithm> #define MAX 500005 using namespace std; struct data { long long sum, prefix_sum, suffix_sum, ans; data(long long val) { sum = val; prefix_sum = suffix_sum = ans = max(0LL, val); } data(long long a, long long b, long long c, long long d) : sum(a), prefix_sum(b), suffix_sum(c), ans(d) {} data(){} }; data tree[4 * MAX]; long long arr[MAX]; data combine(data l, data r) { data res; res.sum = l.sum + r.sum; res.prefix_sum = max(l.prefix_sum, l.sum + r.prefix_sum); res.suffix_sum = max(r.suffix_sum, r.sum + l.suffix_sum); res.ans = max(max(l.ans, r.ans), l.suffix_sum + r.prefix_sum); return res; } void build(long long node, long long tl, long long tr) { if (tl > tr) return; if (tl == tr) tree[node] = data(arr[tl]); else { long long tm = (tl + tr) / 2; build(node * 2, tl, tm); build((node * 2) + 1, tm + 1, tr); tree[node] = combine(tree[node * 2], tree[(node * 2) + 1]); } } data query(long long node, long long tl, long long tr, long long l, long long r) { if (tl > tr || r < tl || l > tr) return data(0, -1e9, -1e9, -1e9); if (tl <= l && r >= tr) return tree[node]; long long tm = (tl + tr) / 2; data n1 = query(node * 2, tl, tm, l, r); data n2 = query((node * 2) + 1, tm + 1, tr, l, r); return combine(n1, n2); } int main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> arr[i]; build(1, 0, n - 1); long long m; cin >> m; while (m--) { long long x, y; cin >> x >> y; cout << query(1, 0, n - 1, x - 1, y - 1).ans << "\n"; } return 0; }

Полный текст и комментарии »

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится