ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

Stupid solution, but it works (С++)
Posted by Maxim 26 Jan 2014 21:41
Find all the "1-positions" and find answers in logN. Total complexity is O(NlogN)

#include <iostream>
#include <set>

using namespace std;

int main() {
    int n; cin >> n;
    set<unsigned int> v;
    unsigned int a = 1, c = 0;
    while(a <= (1<<31)) {
        v.insert( a );
        a += c++;
    }
    for(int i = 0; i < n; ++i) {
        cin >> a;
        if(*v.find(a) == v.size()) {
            cout << 0 << ' ';
        } else {
            cout << 1 << ' ';
        }
    }
}