Submission #26643

# Submission time Handle Problem Language Result Execution time Memory
26643 2017-07-04T00:56:22 Z top34051 Selling RNA Strands (JOI16_selling_rna) C++14
60 / 100
566 ms 68104 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
struct node
{
    int x,id,type;
    node(int _x = 0,int _id = 0,int _type = 0)
    {
        x = _x; id = _id; type = _type;
    }
};
int n,m,sz;
int ans[maxn];
int pos[maxn];
int l[maxn];
int r[maxn];
int tree[maxn*4];
vector<node> p;
vector<node> q;
vector<string> s;
vector<string> t;
bool cmp1(node p1,node p2)
{
    if(s[p1.x]==s[p2.x]) return p1.type<p2.type;
    return s[p1.x]<s[p2.x];
}
bool cmp2(node p1,node p2)
{
    if(t[p1.x]==t[p2.x]) return p1.type<p2.type;
    return t[p1.x]<t[p2.x];
}
void add(int x,int val)
{
    while(x<=sz)
    {
        tree[x] += val;
        x += x&-x;
    }
}
int sum(int x)
{
    int res = 0;
    while(x>0)
    {
        res += tree[x];
        x -= x&-x;
    }
    return res;
}
main()
{
    int i,x;
    string temp,temp2;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    sz = 0;
    for(i=0;i<n;i++)
    {
        cin >> temp;
        s.push_back(temp);       p.push_back(node(sz,i,0));
        reverse(temp.begin(),temp.end());
        t.push_back(temp);       q.push_back(node(sz,i,0));
        sz += 1;
    }
    for(i=0;i<m;i++)
    {
        cin >> temp >> temp2;
        s.push_back(temp);       p.push_back(node(sz,i,-1));
        temp[temp.size()-1]++;
        s.push_back(temp);       p.push_back(node(sz+1,i,1));
        reverse(temp2.begin(),temp2.end());
        t.push_back(temp2);      q.push_back(node(sz,i,-1));
        temp2[temp2.size()-1]++;
        t.push_back(temp2);      q.push_back(node(sz+1,i,1));
        sz += 2;
    }

    sort(&p[0],&p[sz],cmp1);
    sort(&q[0],&q[sz],cmp2);

    for(i=0;i<p.size();i++)
    {
        if(p[i].type==-1) l[p[i].id] = i+1;
        if(p[i].type==0) pos[p[i].id] = i+1;
        if(p[i].type==1) r[p[i].id] = i+1;
    }

    for(i=0;i<q.size();i++)
    {
        x = q[i].id;
        if(q[i].type==-1) ans[x] -= sum(r[x])-sum(l[x]);
        if(q[i].type==0) add(pos[x],1);
        if(q[i].type==1) ans[x] += sum(r[x])-sum(l[x]);
    }

    for(i=0;i<m;i++) cout << ans[i] << endl;
}

Compilation message

selling_rna.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:82:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<p.size();i++)
              ^
selling_rna.cpp:89:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<q.size();i++)
              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5308 KB Output is correct
2 Correct 0 ms 5308 KB Output is correct
3 Correct 0 ms 5308 KB Output is correct
4 Correct 0 ms 5308 KB Output is correct
5 Correct 0 ms 5308 KB Output is correct
6 Correct 0 ms 5308 KB Output is correct
7 Correct 0 ms 5308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 13988 KB Output is correct
2 Correct 33 ms 14868 KB Output is correct
3 Correct 29 ms 14764 KB Output is correct
4 Correct 33 ms 14752 KB Output is correct
5 Correct 36 ms 11964 KB Output is correct
6 Correct 29 ms 12024 KB Output is correct
7 Correct 69 ms 17788 KB Output is correct
8 Correct 53 ms 18892 KB Output is correct
9 Correct 89 ms 18892 KB Output is correct
10 Correct 59 ms 14016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 34024 KB Output is correct
2 Correct 96 ms 19180 KB Output is correct
3 Correct 186 ms 19176 KB Output is correct
4 Correct 89 ms 19176 KB Output is correct
5 Correct 113 ms 19708 KB Output is correct
6 Correct 143 ms 19176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5308 KB Output is correct
2 Correct 0 ms 5308 KB Output is correct
3 Correct 0 ms 5308 KB Output is correct
4 Correct 0 ms 5308 KB Output is correct
5 Correct 0 ms 5308 KB Output is correct
6 Correct 0 ms 5308 KB Output is correct
7 Correct 0 ms 5308 KB Output is correct
8 Correct 19 ms 13988 KB Output is correct
9 Correct 33 ms 14868 KB Output is correct
10 Correct 29 ms 14764 KB Output is correct
11 Correct 33 ms 14752 KB Output is correct
12 Correct 36 ms 11964 KB Output is correct
13 Correct 29 ms 12024 KB Output is correct
14 Correct 69 ms 17788 KB Output is correct
15 Correct 53 ms 18892 KB Output is correct
16 Correct 89 ms 18892 KB Output is correct
17 Correct 59 ms 14016 KB Output is correct
18 Correct 179 ms 34024 KB Output is correct
19 Correct 96 ms 19180 KB Output is correct
20 Correct 186 ms 19176 KB Output is correct
21 Correct 89 ms 19176 KB Output is correct
22 Correct 113 ms 19708 KB Output is correct
23 Correct 143 ms 19176 KB Output is correct
24 Correct 116 ms 19576 KB Output is correct
25 Correct 239 ms 26268 KB Output is correct
26 Correct 86 ms 16504 KB Output is correct
27 Correct 106 ms 19592 KB Output is correct
28 Runtime error 566 ms 68104 KB Execution timed out (wall clock limit exceeded)
29 Halted 0 ms 0 KB -