QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225315#5423. Perfect MatchingHanzoSxCompile Error//C++142.9kb2023-10-24 14:42:172023-10-24 14:42:19

Judging History

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

  • [2023-10-24 14:42:19]
  • 评测
  • [2023-10-24 14:42:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1e5 + 100;
const int inf = 1e9;

inline int read()
{
	int sum = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		sum = sum * 10 + ch - '0';
		ch = getchar();
	} 
	return sum * f;
}
void Print(int x)
{
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) Print(x / 10);
	putchar(x % 10 + 48);
}

int f[2*N];
int find(int x)
{
    return f[x] == x ? x : f[x] = find(f[x]);
}

int num, head[N], to[2*N], nxt[2*N], id[2*N];
void add(int u, int v, int _id)
{
    to[++ num] = v;
    nxt[num] = head[u];
    id[num] = _id;
    head[u] = num;
}

map<int, int> mp;
int mpcnt;

vector<int> vec[2*N];
int d[2*N];

bool vis[2*N], select[N];
void dfs(int t, int fa = 0, int _i = 0)
{
    vis[t] = true;
    for (int i = head[t]; i; i = nxt[i])
        if (to[i] != fa and !vis[to[i]])
            dfs(to[i], t, i);

    if (d[t] % 2 == 0 and _i)
    {
        vec[t].push_back(id[_i]);
        select[id[_i]] = true;
        -- d[t]; -- d[to[_i]];
    }

    for (int i = head[t]; i; i = nxt[i])
        if (!select[id[i]] and to[i] != fa)
        {
            vec[t].push_back(id[i]);
            select[id[i]] = true;
            -- d[t]; -- d[to[i]];
        }
}

int a[N], edge[2*N];

signed main()
{
	int T;
	T = read();
	while (T--)
	{
        mpcnt = 0; mp.clear();
        int n; n = read();

        for (int i = 1; i <= n; ++ i)
            select[i] = false;
        for (int i = 1; i <= 2*n; ++ i)
            f[i] = i, edge[i] = 0, head[i] = 0, vis[i] = false, d[i] = 0;

        for (int i = 1; i <= n; ++ i)
        {
            a[i] = read();
            if (!mp.count(a[i] - i))
                mp[a[i] - i] = ++ mpcnt;
            if (!mp.count(a[i] + i + inf))
                mp[a[i] + i + inf] = ++ mpcnt;

            int u = mp[a[i] - i], v = mp[a[i] + i + inf];
            add(u, v, i); add(v, u, i);
            ++ d[u]; ++ d[v];

            int fu = find(u), fv = find(v);
            f[fu] = fv;
            edge[fv] += edge[fu] + 1;
        }
        
        for (int i = 1; i <= mpcnt; ++ i)
            vec[i].clear();

        bool fres = true;
        for (int i = 1; i <= mpcnt; ++ i)
            if (find(i) == i)
            {
                if (edge[i] & 1)
                {
                    fres = false;
                    printf("No\n");
                    break;
                }
                else
                {
                    dfs(i);
                }
            }

        if (fres)
        {
            printf("Yes\n");
            for (int i = 1; i <= mpcnt; ++ i)
                for (int j = 0, siz = vec[i].size(); j < siz; ++ j)
                    Print(vec[i][j]), putchar(j & 1 ? '\n' : ' ');
        }
	}
	
	return 0;
}

詳細信息

answer.code:52:24: error: ‘bool select [100100]’ redeclared as different kind of entity
   52 | bool vis[2*N], select[N];
      |                        ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:394,
                 from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/sys/select.h:101:12: note: previous declaration ‘int select(int, fd_set*, fd_set*, fd_set*, timeval*)’
  101 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
answer.code: In function ‘void dfs(long long int, long long int, long long int)’:
answer.code:63:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   63 |         select[id[_i]] = true;
      |                      ^
answer.code:63:24: error: assignment of read-only location ‘*(select + ((sizetype)id[_i]))’
   63 |         select[id[_i]] = true;
      |         ~~~~~~~~~~~~~~~^~~~~~
answer.code:68:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   68 |         if (!select[id[i]] and to[i] != fa)
      |                          ^
answer.code:71:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   71 |             select[id[i]] = true;
      |                         ^
answer.code:71:27: error: assignment of read-only location ‘*(select + ((sizetype)id[i]))’
   71 |             select[id[i]] = true;
      |             ~~~~~~~~~~~~~~^~~~~~
answer.code: In function ‘int main()’:
answer.code:88:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   88 |             select[i] = false;
      |                     ^
answer.code:88:23: error: assignment of read-only location ‘*(select + ((sizetype)i))’
   88 |             select[i] = false;
      |             ~~~~~~~~~~^~~~~~~