QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292152#6334. PassportMax_s_xaMCompile Error//C++145.1kb2023-12-27 19:47:432023-12-27 19:47:43

Judging History

你现在查看的是最新测评结果

  • [2023-12-27 19:47:43]
  • 评测
  • [2023-12-27 19:47:43]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <deque>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 2e5 + 10, MAXM = 4e5 + 10;

int n, Q, al[MAXN], ar[MAXN];
int m, idx[MAXN], id[MAXM];

vector < pair <int, int> > e[MAXM], re[MAXM];
inline void AddEdge(int u, int v, int w)
{
    // cout << u << " " << v << " " << w << "\n";
    e[u].push_back(make_pair(v, w));
    re[v].push_back(make_pair(u, w));
}

int tr[MAXN << 2];
void Build(int cur, int l, int r)
{
    tr[cur] = ++m;
    if (l == r) idx[l] = m;
    else
    {
        int mid = l + r >> 1;
        Build(cur << 1, l, mid), Build(cur << 1 | 1, mid + 1, r);
        AddEdge(tr[cur], tr[cur << 1], 0), AddEdge(tr[cur], tr[cur << 1 | 1], 0);
    }
}
void Update(int cur, int l, int r, int x, int y, int k)
{
    if (x <= l && r <= y) AddEdge(idx[k], tr[cur], 1);
    else
    {
        int mid = l + r >> 1;
        if (x <= mid) Update(cur << 1, l, mid, x, y, k);
        if (y > mid) Update(cur << 1 | 1, mid + 1, r, x, y, k);
    }
}

int dis1[MAXM], dis2[MAXM];
deque <int> dq;

int main()
{
    // freopen("C.in", "r", stdin);
    // freopen("C.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n);
    Build(1, 1, n);
    for (int i = 1; i <= n; i++) Read(al[i]), Read(ar[i]), Update(1, 1, n, al[i], ar[i], i);
    m++;
    for (int i = 1; i <= n; i++)
        if (al[i] == 1) re[m].push_back(make_pair(idx[i], 1));
    for (int i = 1; i <= m; i++) dis1[i] = 1e9;
    dis1[m] = 0, dq.push_front(m);
    while (!dq.empty())
    {
        int u = dq.front(); dq.pop_front();
        for (auto t : re[u])
        {
            int v = t.first, w = t.second;
            if (dis1[v] > dis1[u] + w)
            {
                dis1[v] = dis1[u] + w;
                if (!w) dq.push_front(v);
                else dq.push_back(v);
            }
        }
    }
    // for (int i = 1; i <= n; i++) cout << dis1[idx[i]] << " "; cout << "\n";
    re[m].clear();
    for (int i = 1; i <= n; i++)
        if (ar[i] == n) re[m].push_back(make_pair(idx[i], 1));
    for (int i = 1; i <= m; i++) dis2[i] = 1e9;
    dis2[m] = 0, dq.push_front(m);
    while (!dq.empty())
    {
        int u = dq.front(); dq.pop_front();
        for (auto t : re[u])
        {
            int v = t.first, w = t.second;
            if (dis2[v] > dis2[u] + w)
            {
                dis2[v] = dis2[u] + w;
                if (!w) dq.push_front(v);
                else dq.push_back(v);
            }
        }
    }
    // for (int i = 1; i <= n; i++) cout << dis2[idx[i]] << " "; cout << "\n";
    m--;
    // for (int i = 1; i <= m; i++) cout << dis1[i] << " "; cout << "\n";
    // for (int i = 1; i <= m; i++) cout << dis2[i] << " "; cout << "\n";
    for (int i = 1; i <= m; i++) dis1[i] += dis2[i] - 1, id[i] = i;
    sort(id + 1, id + m + 1, [&](int x, int y) {return dis1[x] < dis1[y];});
    for (int i = 1; i <= m; i++)
    {
        for (auto t : re[id[i]])
        {
            int v = t.first, w = t.second;
            dis1[v] = min(dis1[v], dis1[id[i]] + w);
        }
    }
    // for (int i = 1; i <= m; i++) cout << dis1[i] << " "; cout << "\n";
    Read(Q);
    int x;
    while (Q--)
    {
        Read(x);
        Write((dis1[idx[x]] >= 1e9 ? -1 : dis1[idx[x]]), '\n');
    }
    return 0;
}

Details

answer.code:81:1: error: ‘vector’ does not name a type
   81 | vector < pair <int, int> > e[MAXM], re[MAXM];
      | ^~~~~~
answer.code: In function ‘void AddEdge(int, int, int)’:
answer.code:85:5: error: ‘e’ was not declared in this scope
   85 |     e[u].push_back(make_pair(v, w));
      |     ^
answer.code:86:5: error: ‘re’ was not declared in this scope
   86 |     re[v].push_back(make_pair(u, w));
      |     ^~
answer.code: In function ‘int main()’:
answer.code:128:25: error: ‘re’ was not declared in this scope
  128 |         if (al[i] == 1) re[m].push_back(make_pair(idx[i], 1));
      |                         ^~
answer.code:134:23: error: ‘re’ was not declared in this scope
  134 |         for (auto t : re[u])
      |                       ^~
answer.code:137:37: error: ‘w’ was not declared in this scope
  137 |             if (dis1[v] > dis1[u] + w)
      |                                     ^
answer.code:146:5: error: ‘re’ was not declared in this scope
  146 |     re[m].clear();
      |     ^~
answer.code:157:37: error: ‘w’ was not declared in this scope
  157 |             if (dis2[v] > dis2[u] + w)
      |                                     ^
answer.code:176:50: error: ‘w’ was not declared in this scope
  176 |             dis1[v] = min(dis1[v], dis1[id[i]] + w);
      |                                                  ^