11672 - Dynamic Summation... Why RunTime ....

2 views
Skip to first unread message

Angeh A2

unread,
Nov 21, 2009, 3:23:30 AM11/21/09
to aut-a...@googlegroups.com
Hi all ...

11672 - Dynamic Summation... Why RunTime ....
Can someone help me ?!!
 

11672 - Dynamic Summation.cpp

mostafa S.M

unread,
Nov 23, 2009, 12:54:25 PM11/23/09
to aut-a...@googlegroups.com
man motevajeh shodam ke chera Runtime Error migirid !
oon arrey B tooye tabeye insert sizesh kheili kame !
man khodam code in soalo zadam va RUNTE gereftam amma vaghti size arrey ro 1000000 kardam TimeLimit gereftam :D  ,,, dar har soorat AC nasshod

inam code man :

@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int LL;

vector <LL> seq , temp ;
stringstream str;


void ins(string s)
{
    LL temp[1000000] = {0};
    //temp.clear();
    string t;
    str.str(s);
    int pos;
    LL tmp , n , r, m ,a ,c;
    str >> t;
    str >> pos;
    str >> n >> r >> m >> a >> c;
    int i = 0;
    for(int i = 0 ; i < r ; i++)
        str >> temp[i];

    for(int i = r ; i < n ; i++)
    {
        temp[i] = (temp[i-r]*a+c)%m;
        c = ((temp[i-r]*a+c)/m)%m;
    }
    seq.insert(seq.begin() + pos , temp , temp+ n);
    str.clear();
}

void del(string s)
{
    string t;
    str.str(s);
    int first , last;
    str >> t;
    str >> first >> last;
    for(int i = first ; i <= last ; i++)
        seq.erase(seq.begin() + first);

    str.clear();
}

LL sum(string s)
{
    string t;
    str.str(s);
    int first , last;
    str >> t;
    str >> first >> last;
    LL res = 0;
    for(int i = first ; i <= last &&  i < seq.size() ; i++)
        res+= seq[i];

    str.clear();
    return res;
}

int main()
{
    //freopen("seq.in" , "r" , stdin);
    int n , cnt = 1;;
    while(cin >> n , n)
    {
        seq.clear();
        string s,t;
        getline(cin , s);
        printf("Scenario %d:\n",cnt++);
        for(int i = 0 ; i < n ; i++)
        {
            getline(cin , s);
            str.str(s);
            str >> t;
            str.clear();
            if(t == "insert")
                ins(s);
            else if(t == "delete")
                del(s);
            else
                printf("%lld\n",sum(s));
        }
        printf("\n");
    }

    return 0;
}

@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@

 

--

You received this message because you are subscribed to the Google Groups "AUT-ACMICPC" group.
To post to this group, send email to aut-a...@googlegroups.com.
To unsubscribe from this group, send email to aut-acmicpc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/aut-acmicpc?hl=.

338.gif

mostafa S.M

unread,
Nov 23, 2009, 1:05:24 PM11/23/09
to aut-a...@googlegroups.com
Rasti man fekr mikonam ke TL ke man gereftam be khatere kar kardan ba StringStreame chon ba in vazi ke nazdik be 1000000 adad too arrey b bayad berizim pas mosalaman TL bayad bede !
amma motaasefane man kar kardane ba sscanf va gets ro khub balad nistam mishe mano rahnami konid !

Thanks
338.gif

Angeh A2

unread,
Nov 23, 2009, 5:49:59 PM11/23/09
to aut-a...@googlegroups.com
tahala masaleyi nadide boodam ke mardom in hame runtime saresh khorde bashan ........
jalebe !!
merC
338.gif
Reply all
Reply to author
Forward
0 new messages