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 1521. War Games 2

The difference between VC++ and g++
Posted by ONU_1785 10 Mar 2013 07:16
Solved the problem using segment tree.
Im using VC++ 12 and it's giving the correct answer for the sample.
Still while sending (VC++ 2010) im getting WA 1. Changing it to G++ C++ 11 gives AC. What's the difference and why am i getting WA 1 when i choose VC++?

Code:
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=100000;
pair<int, int> t[4*MAXN];
int z=1;


void build_tree(int v, int tl, int tr)
{
    if (tl==tr)
    {
        t[v]=make_pair(1,z++);
        return;
    }
    int tm=(tl+tr)/2;
    build_tree(2*v, tl, tm); build_tree(2*v+1, tm+1, tr);
    t[v].first=t[2*v].first+t[2*v+1].first;
    t[v].second=-1;
}


int req(int v, int tl, int tr, int n)
{
    if (tl==tr)
    {
        --t[v].first;
        return t[v].second;
    }
    int tm=(tl+tr)/2;
    t[v].first--;
    if (t[2*v].first>=n)
        req(2*v, tl, tm, n);
    else
        req(2*v+1, tm+1,tr,n-t[2*v].first);




}


int main()
{
    int n, k; cin>>n>>k;
    build_tree(1,1,100000);
    int cur=k;
    for (int i=0; i<n; ++i)
    {
        int h=req(1,1,100000, cur);
        cout<<h<<" ";
        if (i==n-1)
            break;
        cur=(cur-1+k)%(n-1-i);
        if (cur==0)
            cur+=n-1-i;
    }
}

Edited by author 10.03.2013 07:20
Re: The difference between VC++ and g++
Posted by D4nick 21 May 2023 15:07
Not sure, but it could be because of this t[4*MAXN] instead of t[400000]