m.ajaj94's blog

By m.ajaj94, history, 7 years ago, In English

Hello there

I have a 2D array with dimensions 2500*2500

And i have n < 10000

Now i am given an initial point in the array in the form of x,y and i need to find n points in the array that all points are as far from each other as possible

Bottom line is : i have an array and i need to find n positions in it as scattered as possible

This is not a problem i found on an online judge it's for a project i'm doing and im wondering if theres a way to accomplish this in reasonable complexity

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it

By m.ajaj94, history, 8 years ago, In English

Hello there i'm starting to learn about segment tree and its applications i came across this problem and found very interesting and although i am sure of my solution it keeps getting WA here's the problem

and here is the code

#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9 + 7;
const double eps = 1e-18;
const double PI = atan(1.0);
#define readFile freopen("input","r",stdin);
#define writeFile freopen("output","w",stdout);
#define fastIO ios::sync_with_stdio(0);
typedef unsigned long long ULL;
typedef pair<int,int> ii;


struct Node{
    int sum,ls,rs,best;
    Node(){}
    Node(int sum,int ls,int rs,int best){
        this->sum = sum;
        this->ls = ls;
        this->rs = rs;
        this->best = best;
    }
};

Node merge(Node n1,Node n2){
    int sum,ls,rs,best;
    sum = n1.sum+n2.sum;
    ls = max(n1.ls,n1.sum+n2.ls);
    rs = max(n2.rs,n2.sum+n1.rs);
    best = max(n1.best,max(n2.best,n1.rs+n2.ls));
    return Node(sum,ls,rs,best);
}

const int N = 50001;
int arr[N];
Node tree[N<<2];
int neg = -1000000000;


Node build(int node,int l,int r){
    if (l==r){
        return tree[node] = Node(arr[l],arr[l],arr[l],arr[l]);
    }
    int mid = (l+r) >> 1;
    return tree[node] = merge(build(node<<1,l,mid),build(node<<1|1,mid+1,r));
}

Node query(int node,int l,int r,int ll,int rr){
    if (l>rr || r<ll) return Node(neg,neg,neg,neg);
    if (l>=ll && r<=rr) return tree[node];
    int mid = (l+r) >> 1;
    return merge(query(node<<1,l,mid,ll,rr),query(node<<1|1,mid+1,r,ll,rr));
}


int main(){
#ifndef ONLINE_JUDGE
    readFile; writeFile; 
#endif
    fastIO;
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    build(1,1,n);
    int q; cin>>q;
    while (q--){
        int a,b; cin>>a>>b;
        cout<<query(1,1,n,a,b).best<<"\n";
    }
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By m.ajaj94, history, 8 years ago, In English

Hello there My name is Majd and I am from Syria I am quite fluent at english and have been told by native speakers that I am considered to be as close as it gets to one. I have read numerous blogs on Codeforces where people are asking for language experience in exchange for tutoring in competitive programming, which is exactly what I'm looking for at the moment. If you find my offer interesting, then let's have a talk :D

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By m.ajaj94, history, 8 years ago, In English

Hello There i have fallen madly in love with competitive programming and have been training hard for the past year, the thing is first six months i have noticed a difference in the way i think and the way i approach a problem... but after that it feels like i'm stuck in my place with no noticeable difference my way of working is that i participate in every round on codeforces and end up probably solving Problems A and B, sometimes C but only when C is relatively easy. i try to get more knowledgeable by reading about different topics, data structures and algorithms online, and by reading the book Competitive Programming 3 and trying to solve its problems. The issue is i still can't really see any noticeable improvement. Is this the proper way for practicing ? am i speaking too soon because it takes more than a year to accomplish this feat ? or is there another way i should be doing this ? I aspire to reach ICPC one day but i am 21 years old now... could this be accomplished in your opinion ?

Full text and comments »

  • Vote: I like it
  • -10
  • Vote: I do not like it

By m.ajaj94, 9 years ago, In English

I'm kind of a newbie and new to graph my submission gives runtime error if it isn't too much trouble can anyone help me and explain the reason ??

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By m.ajaj94, 10 years ago, In English

hello there : i'm trying to solve the trees in a row problem http://codeforces.com/contest/402/problem/B and after numerous tries i am still trying to find the cause of the runtime error i am facing at test case 6 ... any help would be appreciated :)

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it