Posts

Showing posts with the label riddle series

Some stuff.

#include <iostream> using namespace std; int a[20000]; bool in_heap[20000]; int n; inline void swap(int& x, int& y) { int tmp = x; x = y; y = tmp; } void maintain(int i) {     /*cout << endl << endl;     cout << "Maintaining node " << i << endl;     cout << "Current heap: ";     cout << a[1];     for(int i = 2; i <= n; i++) cout << ", " << a[i];     cout << endl;*/     while(i < n)     {         int m, c;         /*cout << "\tStats:" << endl;         cout << "\t\tCurrently at node " << i << endl;         cout << "\t\tCurrent node value: " << a[i] << endl;         cout << "\t\tParent: " << i/2 << endl;         cout ...

To Increment or Not to Increment

To Increment or Not to Increment S o, I re-did POJ 2352 (Stars) today, and got a time limit exceeded error. See the post earlier for a recap. I spent a hour debugging while loops, no luck. It's the only source of infinite loops, after all. ARRGGHH So, here's my code: #include <cstdio> using namespace std; int BIT[33001]; int ans[15001]; void incr(int ind) { while(ind<33000) {  BIT[ind]++; ind += (ind&(-ind)); } } int get(int ind) { int res=0; while(ind) { res += BIT[ind]; ind -= (ind&(-ind)); } return res; } int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) { int x, y; scanf("%d %d",&x, &y); ans[get(x)]++; incr(x); } for(int i=0;i<n;i++) printf("%d\n",ans[i]); } Ahem. See that disturbing red line over there? "No?" Maybe you're color blind. Okay. But anyways, this little monster here: ans[get(x)]++; Read that line ten times, then read th...