답안 #81488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81488 2018-10-25T03:25:40 Z luckyboy Automobil (COCI17_automobil) C++14
40 / 100
8 ms 988 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 500005
#define pii pair <long long,long long>
#define Task "Automobil"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
long long ans,n,m,q,ta,tb;
pii a[maxn],b[maxn];
void Recode(pii x[],long long &sz)
{
    sort(x+1,x+sz+1);
    int cnt = 0;
    FOR(i,1,sz)
    {
        int cur = 1,r = i;
        while (r <= sz && x[r].F == x[i].F)
        {
            cur = (1ll*cur*x[r].S) % maxc;
            ++r;
        }
        x[++cnt] = mp(x[i].F,cur);
        i = r - 1;
    }
    sz = cnt;
}
long long Get(long long l,long long r,long long dis)
{
    long long res;
    long long ssh = (r - l) / dis + 1;
    if (ssh & 1)
    {
        res = (l+r) / 2;
        res = res * ssh % maxc;
    }
    else
    {
        res = ssh / 2;
        res %= maxc;
        res = res * (r + l) % maxc;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    cin >> n >> m >> q;
    FOR(i,1,q)
    {
        char c;
        long long x,y;
        cin >> c >> x >> y;
        if (c == 'R') a[++ta] = mp(x,y);
        else b[++tb] = mp(x,y);
    }
    Recode(a,ta);
    Recode(b,tb);
    ans = Get(1,n*m,1);
    FOR(i,1,ta)
    {
        long long sum = Get(1ll*m*a[i].F - m + 1,1ll*m*a[i].F,1);
        ans = (ans - sum + maxc) % maxc;
        sum = (sum * a[i].S) % maxc;
        ans = (ans + sum) % maxc;
    }
    FOR(i,1,tb)
    {
        long long sum = Get(b[i].F,b[i].F + 1ll*(n-1)*m,m);
        ans = (ans - sum + maxc) % maxc;
        sum = (sum * b[i].S) % maxc;
        ans = (ans + sum) % maxc;
    }
    FOR(i,1,ta)
        FOR(j,1,tb)
        {
            long long u = a[i].F,v = b[j].F;
            long long old = (1ll*(u-1)*m + v) % maxc;
            long long ne = (old * b[j].S) % maxc;
            ans = (ans - ne + old + maxc) % maxc;
            old = (old * a[i].S) % maxc;
            ne = (old * b[j].S) % maxc;
            ans = (ans - old + ne) % maxc;
        }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 516 KB Output is correct
3 Incorrect 3 ms 516 KB Output isn't correct
4 Correct 3 ms 520 KB Output is correct
5 Correct 3 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Incorrect 4 ms 616 KB Output isn't correct
8 Incorrect 2 ms 616 KB Output isn't correct
9 Correct 3 ms 660 KB Output is correct
10 Correct 4 ms 660 KB Output is correct
11 Incorrect 4 ms 688 KB Output isn't correct
12 Incorrect 6 ms 700 KB Output isn't correct
13 Correct 3 ms 720 KB Output is correct
14 Incorrect 2 ms 732 KB Output isn't correct
15 Incorrect 5 ms 732 KB Output isn't correct
16 Incorrect 6 ms 752 KB Output isn't correct
17 Incorrect 7 ms 772 KB Output isn't correct
18 Incorrect 8 ms 804 KB Output isn't correct
19 Incorrect 6 ms 824 KB Output isn't correct
20 Incorrect 6 ms 988 KB Output isn't correct