ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1003. Чётность

1003 : Why TLE??
Послано Pungaru Marius 6 фев 2005 16:28
Hi!I solved this problem in O(N ^ 2) but still get TLE! Is there a faster way to solve this problem?(maybe you have a tricky test for this problem altrough i don't think my source code produces an infinte cycle).
10x in advance!
Give me your code, and I will hepl you. My e-mail: marilyn_manson@bk.ru (-)
Послано Victor Barinov (TNU) 6 фев 2005 17:27
Re: Give me your code, and I will hepl you. My e-mail: marilyn_manson@bk.ru (-)
Послано Pungaru Marius 6 фев 2005 20:15
Sorry! i don't know why but my mail server has some troubles sending my message to you.Look what i got when i tried to send a message to you.

Hi. This is the qmail-send program at mail.rdslink.ro.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<marilyn_manson@bk.ru>:
194.67.23.20 does not like recipient.
Remote host said: 550 Access from ip address 193.231.236.20 blocked. Visit http://win.mail.ru/cgi-bin/support_bl?ip=193.231.236.20
Giving up on 194.67.23.20.

Here is what was writen in the mail:
Thanks for responding on the timus forum!Since a posted that topic i worked a lot on the source code, and generated a lot of special cases,and i found that i have one small bug which was generating an infinite cycle but i solved the problem.But i have a new one -> i send the very-tested source to timus and the evaluation system returned ACCES_VIOLATION.I know that this means that my program is trying to acces undeclared memory,but i really don't know how to solve this probelm beacuse i don't know where it occurs.I have the same bug on problem 1004 and i still haven' fixed it.In the attachment you have my source code.
10x for helping me! Marius Pungaru

And here is the source code(which doesn't works):
#include <stdio.h>
#include <string.h>

#define LMAX 100
#define NMAX 5002

struct Query
{
    char parity;
    long start, stop;
};

char str[LMAX];
struct Query Q[NMAX];
long range, q, i, j, nok, ok, step, N;

void swap(int l, int r)
{
    struct Query aux;

    aux = Q[l], Q[l] = Q[r], Q[r] = aux;
}

int main(void)
{
    for (scanf("%ld", &range) ; range != -1 ; scanf("%ld", &range))
    {
        scanf("%ld\n", &N);
        for (j = nok = 0 , q = -1 ; j < N && !nok ; j++)
        {
            q++, scanf("%ld %ld %s", &Q[q].start, &Q[q].stop, str);
            Q[q].parity = strcmp(str, "even") ? 1 : 0;

            /* binary search for the lowest element i with Q[i].start <= Q[q].start */
            for (step = 1 ; step <= q + 1 ; step <<= 1) ;
            for (i = q ; step ; step >>= 1)
                if (i - step >= 0 && Q[i - step].start >= Q[q].start)
                   i -= step;

            /* make reductions & stuff */
            for ( ; (!nok) && i < q && Q[i].start == Q[q].start ; )
            {
                if (Q[i].stop == Q[q].stop)
                   nok = Q[i].parity == Q[q].parity ? 0 : 1, i = --q;
                else
                if (Q[i].stop < Q[q].stop)
                   Q[q].start = Q[i].stop + 1, Q[q].parity = Q[q].parity ^ Q[i].parity;
                else swap(i, q);

                for ( ; i < q && Q[i].start < Q[q].start ; i++) ;
            }

            /* bubble sort */
            for (ok = 1 ; ok ; )
                for (ok = 0, i = 1 ; i <= q ; i++)
                    if (Q[i - 1].start > Q[i].start)
                       ok = 1, swap(i - 1, i);
        }
        for (i = j , q++ ; i < N ; i++)
            scanf("%ld %ld %s", Q[q].start, Q[q].stop, str);

        printf("%ld\n", j - (nok ? 1 : 0));
    }

    return 0;
}
// Sorry for the long topic from above
Try this test.
Послано Victor Barinov (TNU) 6 фев 2005 21:11
10
2
2 5 even
2 5 odd
10
3
2 5 even
6 8 odd
3 7 odd
2 8 even
-1
Re: Try this test.
Послано Pungaru Marius 7 фев 2005 20:30
There is one little problem with your test-> the number of questions you say you will ask is 3 and in fact you ask 4 questions.I replaced 3 with 4 and my program produced the correct answer.Should i change my program to accept this kind of incorrect inputs??
Oh! I'm sorry! (+)
Послано Victor Barinov (TNU) 7 фев 2005 23:08
I'm sorry for my mistake. Get tests from CEOI1999. There it is possible to find the test on which your program receives CRASH. Or post your e-mail, I will mail you...
Re: 1003 : Why TLE??
Послано Yaroslavtsev Grigory (SpbSPU) 8 фев 2005 20:40
I think that O(N^2) can't get accepted here at all, because N=5000 and there are multiple tests. My own algo was O(N*logN), but the constant was rather large, so I got AC in 0,234 sec.
Re: Oh! I'm sorry! (+)
Послано Pungaru Marius 9 фев 2005 02:37
my e-mail is : jeuletz@rdslink.ro